无法跟踪 Git 子模块中的文件

发布于 2024-07-26 08:37:02 字数 1745 浏览 9 评论 0原文

问题:./shells/smallApps/*处的文件添加到./.git/处的Git中,但我没有以下位置的文件./.git/info/exclude 也不在任何 .gitignore -文件中。

这个问题是基于 这个步骤 问题所在并没有彻底解决。

我运行

$git status                                                                                                                                          ~/bin
# On branch master
nothing to commit (working directory clean)
$git ls-files                                                                                                                                        ~/bin
Screen/dev/vim-open.screen
--- cut ---

我注意到我的 Git 上没有文件“shells/smallApps/*”

$ls shells/smallApps/                                                                                                                                ~/bin
devTodo     extract     
                                                                                                                                             ~/bin

我想通过运行将它们添加到我的 Git

$git add shells/smallApps/devTodo shells/smallApps/extract
fatal: Path 'shells/smallApps/devTodo' is in submodule 'shells/smallApps'
$git add .         

我注意到由于某种原因这些文件没有添加到我的 Git,因此

$git status                                                                                                                                          ~/bin 
# On branch master
nothing to commit (working directory clean)

我不文件位于 .git/info/exclude 或 .gitignore -files 处。

最后一个警告是什么意思?

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.

This question is based on this tread where 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

$ls shells/smallApps/                                                                                                                                ~/bin
devTodo     extract     
                                                                                                                                             ~/bin

I want to add them to my Git by running

$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 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.

What does the last warning mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

煮茶煮酒煮时光 2024-08-02 08:37:03

更新

Git 忽略文件的一般原因有两个: gitignore子模块

更具体地说,以下条件将导致 Git 在调用“git add”时忽略文件:

  1. 文件与模式 $GIT_DIR/exclude 匹配。
  2. 该文件与存储库内的 .gitignore 文件中的模式匹配。
  3. 该文件与用户特定的 .gitignore 文件(由“git config --global core.excludesfile”指定)中的模式匹配。
  4. 该文件是子模块的一部分。

在被忽略的文件上强制使用“git add”:

您可以通过调用“git add full/path/to/file”来检查特定文件是否被忽略。

手册页指出“如果在命令行上显式指定了被忽略的文件,该命令将失败并显示被忽略文件的列表。”

如果该文件被忽略,您可以强制添加它使用“git add --force full/path/to/file”。

消除子模块引用的说明:

如之前的答案所述,shells/smallApps子模块

如果该文件是子模块的一部分,情况会更复杂。 您无法从主项目中修改子模块的内容。

如果您想消除子模块引用并直接跟踪主存储库中的文件,则必须执行几个步骤。 您不能简单地从子模块中删除“.git”目录。 主存储库和子模块之间存在三个链接:

  1. 主存储库中的 .gitmodules 文件。
  2. 主存储库的 .git/config 中的条目。
  3. 与主存储库历史记录中的子模块相关的任何提交。

根据这个相关SO问题,您需要执行以下步骤完全删除子模块:

注意:如果另一个分支依赖于该子模块,那么删除它可能会损坏您的存储库! 这是一个危险的操作...请谨慎使用。

  1. .gitmodules 文件中删除相关行。
  2. 从 .git/config 中删除相关部分。
  3. 运行 git rm --cached path_to_submodule (无尾部斜杠)。
  4. 提交

属于子模块一部分的文件现在未被跟踪,您可以决定根据需要保留或删除它们(带有下面提到的一个警告)。

如果您不需要这些文件,只需删除它们即可。

警告:如果您想保留这些文件(您似乎想要),则必须从子模块文件夹中手动删除 .git 目录:

  1. cd path_to_submodule< /code>
  2. rm .git
  3. cd ..
  4. git add path_to_submodule
  5. git status
  6. git commit >

更新:

请求更多信息:

为了帮助调试此问题,请发布以下完整命令会话的输出:

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

根据您迄今为止所做的描述,我希望看到:

  • 任何地方都没有 .gitmodules 文件
  • 只有一个 .git 目录(位于存储库的根目录)
  • editors/ 中没有 .git 目录vim/vimdoclet
  • shells/smallApps 中没有 .git 目录

UPDATE

There are two general reasons why Git will ignore a file: gitignore and submodules.

To be more specific, the following conditions will cause Git to ignore a file when 'git add' is invoked:

  1. The file matches a pattern $GIT_DIR/exclude.
  2. The file matches a pattern in a .gitignore file inside the repo.
  3. The file matches a pattern in a user-specific .gitignore file (specified by 'git config --global core.excludesfile').
  4. The file is part of a submodule.

Forcing 'git add' on an ignored file:

You can check to see if a particular file is ignored by invoking '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'.

Instructions to eliminate a submodule reference:

As noted in a previous answer, shells/smallApps is a submodule in your repository.

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:

  1. The .gitmodules file in your main repo.
  2. An entry in the .git/config of your main repo.
  3. Any commits related to the submodule in your main repo history.

Per this related SO question, you need to perform the following steps to completely remove the sub-module:

NOTE: If another branch depends on this submodule, then removing it can corrupt your repository! This is a dangerous operation...use with caution.

  1. Delete the relevant line from the .gitmodules file.
  2. Delete the relevant section from .git/config.
  3. Run git rm --cached path_to_submodule (no trailing slash).
  4. Commit

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:

  1. cd path_to_submodule
  2. rm .git
  3. cd ..
  4. git add path_to_submodule
  5. git status
  6. 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 in editors/vim/vimdoclet
  • No .git directory in shells/smallApps
旧城烟雨 2024-08-02 08:37:03

我看到你有 git add 说了一些关于子模块的事情。 你有嵌套的 Git 存储库吗? 这样做:

$ find . -name .git

列出了多少个 .git 目录? 如果有多个,那么您就有多个嵌套存储库,这可能是造成某些混乱的原因。

I see you've got git add saying something about submodules. Do you have nested Git repositories? Do this:

$ 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.

冷清清 2024-08-02 08:37:03

您应该考虑将此问题发布到 Git 邮件列表 ([email protected]< /a>)。 您可能会得到更迅速、更完整的答复。

如果您决定在那里发帖,请务必包括: 对

  • 您想要实现的目标的描述。
  • 您遇到的问题的描述。
  • 完整的会话日志显示:
    • cd 到存储库的顶级目录
    • ls -al
    • cat .git/config
    • 查找 . -名称“.git*”
    • git 状态
    • git add 编辑器
    • git add shell
    • git 状态

You should consider posting this question to the Git mail list ([email protected]). You will likely get a more prompt and complete response.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文