无法跟踪 Git 子模块中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1084969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to track files within Git submodules
提问by Léo Léopold Hertz ??
Problem:to add files at ./shells/smallApps/*
to Git at ./.git/
when I do not have the files at ./.git/info/exclude
nor at any .gitignore
-files.
问题:当我没有文件 at或任何-files时,将文件添加./shells/smallApps/*
到 Git 。./.git/
./.git/info/exclude
.gitignore
This question is based on this treadwhere the problem is not solved completely.
这个问题是基于这个问题没有完全解决的问题。
I run
我跑
$git status ~/bin
# On branch master
nothing to commit (working directory clean)
$git ls-files ~/bin
Screen/dev/vim-open.screen
--- cut ---
I note that I do not have the files "shells/smallApps/*" at my Git
我注意到我的 Git 中没有文件“shells/smallApps/*”
$ls shells/smallApps/ ~/bin
devTodo extract
~/bin
I want to add them to my Git by running
我想通过运行将它们添加到我的 Git 中
$git add shells/smallApps/devTodo shells/smallApps/extract
fatal: Path 'shells/smallApps/devTodo' is in submodule 'shells/smallApps'
$git add .
I note that the files are not added to my Git for some reason such that
我注意到由于某种原因这些文件没有添加到我的 Git 中
$git status ~/bin
# On branch master
nothing to commit (working directory clean)
I do not have the files at .git/info/exclude nor at .gitignore -files.
我没有 .git/info/exclude 和 .gitignore -files 中的文件。
What does the last warning mean?
最后一个警告是什么意思?
回答by Tim Henigan
UPDATE
更新
There are two general reasons why Git will ignore a file: gitignore
and submodules
.
Git 忽略文件的一般原因有两个:gitignore
和submodules
.
To be more specific, the following conditions will cause Git to ignore a file when 'git add
' is invoked:
更具体地说,以下条件将导致 Git 在git add
调用' '时忽略文件:
- The file matches a pattern
$GIT_DIR/exclude
. - The file matches a pattern in a
.gitignore
file inside the repo. - The file matches a pattern in a user-specific
.gitignore
file (specified by 'git config --global core.excludesfile
'). - The file is part of a submodule.
- 该文件匹配一个模式
$GIT_DIR/exclude
。 - 该文件与
.gitignore
存储库内文件中的模式匹配。 - 该文件与用户特定
.gitignore
文件(由“git config --global core.excludesfile
”指定)中的模式匹配。 - 该文件是子模块的一部分。
Forcing 'git add
' on an ignored file:
git add
在被忽略的文件上强制使用 ' ':
You can check to see if a particular file is ignored by invoking 'git add full/path/to/file
'.
您可以通过调用“ git add full/path/to/file
”来检查特定文件是否被忽略。
The man page states that "If an ignored file is explicitly specified on the command line, the command will fail with a list of ignored files."
手册页指出“如果在命令行上明确指定了一个被忽略的文件,该命令将失败并显示一个被忽略的文件列表。”
If the file is ignored, you can force it to be added with 'git add --force full/path/to/file
'.
如果文件被忽略,您可以强制使用“ git add --force full/path/to/file
”添加它。
Instructions to eliminate a submodule reference:
消除子模块引用的说明:
As noted in a previous answer, shells/smallApps
is a submodulein your repository.
如上一个答案所述,shells/smallApps
是您存储库中的一个子模块。
If the file is part of a submodule, the situation is more complex. You cannot modify the contents of the submodule from within the main project.
如果文件是子模块的一部分,情况就更复杂了。您不能从主项目中修改子模块的内容。
If you want to eliminate the submodule reference and directly track the files in your main repo, there are several steps that must be performed. You cannot simply remove the ".git" directory from the submodule. There are three links between your main repository and the submodule:
如果要消除子模块引用并直接跟踪主存储库中的文件,则必须执行几个步骤。您不能简单地从子模块中删除“.git”目录。主存储库和子模块之间有三个链接:
- The
.gitmodules
file in your main repo. - An entry in the
.git/config
of your main repo. - Any commits related to the submodule in your main repo history.
.gitmodules
主存储库中的文件。.git/config
主存储库中的条目。- 与主仓库历史记录中的子模块相关的任何提交。
Per this related SO question, you need to perform the following steps to completely remove the sub-module:
根据此相关 SO 问题,您需要执行以下步骤以完全删除子模块:
NOTE: If another branch depends on this submodule, then removing it can corrupt your repository! This is a dangerous operation...use with caution.
注意:如果另一个分支依赖于这个子模块,那么删除它会破坏你的存储库!这是一个危险的操作...谨慎使用。
- Delete the relevant line from the
.gitmodules
file. - Delete the relevant section from
.git/config
. - Run
git rm --cached path_to_submodule
(no trailing slash). - Commit
- 从
.gitmodules
文件中删除相关行。 - 从 中删除相关部分
.git/config
。 - 运行
git rm --cached path_to_submodule
(没有尾部斜杠)。 - 犯罪
The files that were part of the submodule are now untracked and you may decide to keep or delete them as desired (with the one caveat mentioned below).
作为子模块一部分的文件现在未被跟踪,您可以根据需要决定保留或删除它们(下面提到的一个警告)。
If you don't need these files, you may simply delete them.
如果您不需要这些文件,您可以简单地删除它们。
Caveat:If you want to keep these files (which you appear to want), you must manually remove the .git
directory from the submodule folder:
警告:如果您想保留这些文件(您似乎想要),您必须手动.git
从子模块文件夹中删除该目录:
cd path_to_submodule
rm .git
cd ..
git add path_to_submodule
git status
git commit
cd path_to_submodule
rm .git
cd ..
git add path_to_submodule
git status
git commit
UPDATE:
更新:
Request for further information:
索取更多资料:
To assist debugging this issue, please post the output of the following complete session of commands:
为了帮助调试此问题,请发布以下完整命令会话的输出:
cd to the top-level directory in your repo
ls -al
cat .git/config
find . -name ".git*"
git status
git add editors
git add shells
git status
Based on the description of what you have done so far, I expect to see:
根据您到目前为止所做的工作的描述,我希望看到:
- No
.gitmodules
file anywhere - Only one
.git
directory (found at the root of your repo) - No
.git
directory ineditors/vim/vimdoclet
- No
.git
directory inshells/smallApps
- 任何
.gitmodules
地方都没有文件 - 只有一个
.git
目录(在你的 repo 的根目录下) - 没有
.git
目录editors/vim/vimdoclet
- 没有
.git
目录shells/smallApps
回答by Greg Hewgill
I see you've got git add
saying something about submodules. Do you have nested Git repositories? Do this:
我看到你在git add
谈论子模块。你有嵌套的 Git 存储库吗?做这个:
$ find . -name .git
How many .git
directories are listed? If there is more than one, then you've got multiple nested repositories and that could be a cause of some of this confusion.
.git
列出了多少个目录?如果有多个,那么您有多个嵌套的存储库,这可能是造成这种混乱的原因之一。
回答by Tim Henigan
You should consider posting this question to the Git mail list ([email protected]
). You will likely get a more prompt and complete response.
您应该考虑将此问题发布到 Git 邮件列表 ( [email protected]
)。您可能会得到更及时、更完整的回复。
If you do decide to post there, be sure to include:
如果您决定在那里发帖,请务必包括:
- A description of what you are trying to achieve.
- A description of the problem you have encountered.
- A complete session log showing:
- cd to the top-level directory in your repo
ls -al
cat .git/config
find . -name ".git*"
git status
git add editors
git add shells
git status
- 对您要实现的目标的描述。
- 您遇到的问题的描述。
- 完整的会话日志显示:
- cd 到你的 repo 中的顶级目录
ls -al
cat .git/config
find . -name ".git*"
git status
git add editors
git add shells
git status