如何修复git中的"修改内容,未跟踪内容"?

Ayu*_*ush 11 git git-submodules

目标是提交一个git分支.分支的"git status"输出为:

On branch zeromq_new
Your branch is up to date with 'origin/zeromq'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

      modified:   log4cplus (modified content, untracked content)
      modified:   ../lib/notification/cppzmq (modified content)
Run Code Online (Sandbox Code Playgroud)

目录结构如下所示:

HySecureGateway
???fes
?   ???log4cplus
?       ???.git
?       ???.gitattributes
?       ???.gitignore
?       ???.gitmodules
?       ???catch
?       ?   ???.git
?       ?   ???.gitattributes
?       ?   ???.github
?       ?   ???.gitignore
?       ?   ???.github
?       ?       ???issue_template.md
?       ?       ???pull_request_template.md
?       ???threadpool
?           ???.github
???lib
    ???notification
        ???cppzmq
            ???.git
            ???.gitignore
Run Code Online (Sandbox Code Playgroud)

我在这里读到了一个类似问题的答案:

如何跟踪未跟踪的内容?,

并完全无法理解.logc4plus/.gitmodules还包含:

[submodule "threadpool"]

        path = threadpool
        url = https://github.com/log4cplus/ThreadPool.git

[submodule "catch"]

        path = catch
        url = https://github.com/philsquared/Catch.git
Run Code Online (Sandbox Code Playgroud)

Bis*_*ina 33

从子文件夹中删除 .git。这对我有用。

  • 就如此容易 (2认同)
  • 美好的。为我的解决方案工作。 (2认同)
  • 这对我来说是工作。 (2认同)

xpl*_*er1 25

我做的是跑:

git rm -rf --cached myuntrackedfolder
Run Code Online (Sandbox Code Playgroud)

这告诉git忘记它(因为它正在被正式跟踪).

然后我用了:

git add myuntrackedfolder 
Run Code Online (Sandbox Code Playgroud)

添加它,我很高兴去.

  • 虽然这确实解决了问题,但它并不能解释出了什么问题;为什么问题首先发生。这肯定与 Git 搞砸了一些事情有关。有谁关心/可以详细说明为什么会发生这种情况吗? (6认同)
  • @SimonC。我相信这通常是由同一目录或子目录中有多个存储库引起的。就我自己而言,我在两个不同的目录中有两个单独的git repos。但是我搬进了另一个。因此,当我运行git &lt;command&gt;时,它会混淆使用哪个存储库。上面的命令然后尝试从其中一个目录中删除git,然后将其重新添加(以防您要将所有内容推送到一个目录中)。我希望我的解释是可以接受的。 (6认同)
  • 也可能是因为您在此文件夹中有一个.git (2认同)

Qua*_*uan 5

解决方案涉及从带有“已修改的内容,未跟踪的内容”标签的目录中删除.git /,从这些目录中删除--cached文件,然后git add再次在这些目录上运行。

分步解决方案:

  1. 从log4cplus和../lib/notification/cppzmq中删除.git /。
  2. 在初始化git存储库的父目录中,运行以下命令: git rm -rf --cached log4cplus/ && git rm -rf --cached ../lib/notifications/cppzmq
  3. 将目录再次添加并提交到您的分支。
  4. 推送到您的分支。

快乐的编码。


Tai*_*ger 5

出于某种原因,这些单独的存储库更改了文件。有几种方法可以处理它,具体取决于它们的实际情况。

您可以导航到每个存储库并查看更改了哪些文件。然后您可以提交、创建新分支或删除更改。

如果这些 repos 是您想要跟踪但不想弄乱的单独项目,您可以使您的父 repo 简单地忽略这些子模块中的更改:

git update-index --assume-unchanged $DIRECTORY

(其中 $DIRECTORY 是您要忽略更改的子模块)