如何在.git目录中添加文件以跟踪它? [英] How to Add a File in .git Directory to Track It?

查看:1088
本文介绍了如何在.git目录中添加文件以跟踪它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要跟踪 .git / 目录(.gitkeep)中的单个文件,但我无法想出一个办法。



原因是我有一个需要 .git / 目录的样板,因为第三方UI模块初始化 git init ,我告诉它。问题是,如果该目录不存在,则默认情况下,init会失败到另一个目录,然后跟踪树从我需要的位置变为不正确。 (,我知道。),但是我需要为应用程序安装一个空的 .git / 目录。



我尝试了以下方法:

  $ git add web / app / .git / .gitkeep 

但我收到:


以下路径会被一个.gitignore文件忽略:
web / app / .git / .gitkeep使用-f if你真的想添加它们。

因为我没有,所以这是不正确的。 gitignore



接下来我试过了:

  $ git add web / app / .git / .gitkeep -f 


$
$ b


错误:无效路径'web / app / b $ b

git的/ .gitkeep错误:无法
网络/应用/ git的/ .gitkeep添加到索引致命的:添加文件失败。




这是不正确的或者,该文件是有效的。



任何想法都会非常有帮助。我想只是手动添加到远程回购,但我认为(??)这会导致问题...?



更新:



我没有说 需要在 .git / 我们的应用安装。我知道推送 .git 目录是一个很差的安全性否否 - 特别是。当我宣讲它时,由于上述原因,我只需要将空的 .git 目录推入回购。



有关那些谁需要空的.git / 目录中并且被使用作曲,请参阅我的回答

解决方案

您不应该在.git文件夹中有任何文件!!!



以下是有关此文件夹内容的详细信息:

http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory。 html






此文件夹仅供内部使用以存储git内容等等。

从下面的a



当混淆Git内部时,只需要一句智慧: 确保你知道你在做什么 ,如果没有,请备份!乱搞配置文件或钩子非常简单,但如果我不需要,我不会在数据存储区中进行探测。如果由于某种原因,您是正常工作流程的一部分,那么您可能会犯错。


文章:



< img src =https://i.stack.imgur.com/HMoJg.pngalt =在这里输入图片描述>


I need to track a single file in the .git/ directory (a .gitkeep) but I cannot figure a means to do so.

The reason is I have a boilerplate that needs the .git/ directory because a "third-party UI module" initiates git init where I tell it. The problem is if the directory does not exist, the init fails by default to another directory and then the tracking tree becomes incorrect from what I need. (Weird, I know.) however I need to have an empty .git/ directory for the application install.

I have tried the following:

$ git add web/app/.git/.gitkeep

But I receive a:

The following paths are ignored by one of your .gitignore files: web/app/.git/.gitkeep Use -f if you really want to add them.

This is not true since I do not have a .gitignore.

Next I tried:

$ git add web/app/.git/.gitkeep -f

..And I get:

error: Invalid path 'web/app/.git/.gitkeep' error: unable to add web/app/.git/.gitkeep to index fatal: adding files failed

This is not true either, the file is valid.

Any ideas would be very helpful. I thought to just add it manually to the remote repo but I think(??) this would cause issues...?

UPDATE:

I failed to say that the .git/ directory was needed to exist after our application install. I understand that pushing the .git directory is a bad security No No - esp. when I preach it but I was only needing to push an empty .git directory to the repo for the reason stated above.

For those who need an empty .git/ directory and is using Composer, see my answer below.

解决方案

You should not have any files inside .git folder !!!

Here is a very detailed post about the content of this folder:
http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html


This folder is for internal use only to store the git content and more.


From the below article:

Just one word of wisdom when messing around with Git internals: make sure you know what you’re doing, and if not, have a backup! Messing around with the config files or hooks is pretty simple but I wouldn’t go spelunking in the datastore if I didn’t have to. If for some reason you are as part of your normal workflow, you might be doing it wrong.

Screen shot from this article:

这篇关于如何在.git目录中添加文件以跟踪它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆