本文介绍了无法跟踪Git子模块内的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ./。shells / smallApps / * 中添加文件到 ./。git / 当我没有在 ./。git / info / exclude 以及任何 .gitignore -files。



这个问题是基于和。



更具体地说,会导致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 '。



消除子模块的说明rence:



正如前面的回答所指出的, shells / smallApps 是一个。

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



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


  1. .gitmodules 文件存储在主要的仓库中。

  2. 主要仓库的 .git / config 中的一个条目。 b
  3. 任何与主repo历史记录中的子模块有关的提交。

根据,您需要执行以下步骤以完全删除子模块:



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


  1. 从 .gitmodules file。

  2. 删除 .git / config 中的相关部分。

  3. 运行 git rm --cached path_to_submodule (无结尾斜杠)。
  4. 提交

子模块的一部分文件现在未被跟踪,您可以根据需要决定是保留还是删除它们(以下提到的一个注意事项) p>

如果您不需要这些文件,您可以直接删除它们。



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


  1. cd path_to_submodule

  2. rm .git

  3. cd ..

  4. git add path_to_submodule

  5. git status

  6. git commit



  7. 更新:



    请求更多信息:



    ,请发布以下完整命令的输出:

      cd到您的仓库中的顶层目录
    ls -al
    cat .git / config
    find。 -name.git *
    git status
    git add editors
    git add shells
    git status

    根据你到目前为止所做的工作描述,我期望看到:


    • 没有 .gitmodules 任何文件
    • 只有一个 .git 目录)

    • 否 .git editors / vim / vimdoclet
    • 没有 .git 目录位于 shells / smallApps


    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?

    解决方案

    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

    这篇关于无法跟踪Git子模块内的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:34