如何在 git 中修复 "modified content, untracked content"?

How to fix "modified content, untracked content" in git?

objective是提交一个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)

目录结构如下所示:

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

我在这里阅读了对类似问题的回答:

How to track untracked content? ,

完全看不懂。 logc4plus/.gitmodules 也包含这个:

[submodule "threadpool"]

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

[submodule "catch"]

        path = catch
        url = https://github.com/philsquared/Catch.git

我所做的是运行:

git rm -rf --cached myuntrackedfolder

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

然后我用了:

git add myuntrackedfolder 

添加它,我很高兴。

解决方案包括从带有 "modified content, untracked content" 标签的目录中删除 .git/,从这些目录中删除 --cached 文件,然后 运行ning git add再次在这些目录上。

分步解决方案:

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

编码愉快。

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

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

如果这些存储库是您想要跟踪但不想搞乱的独立项目,您可以让您的父存储库简单地忽略这些子模块中的更改:

git update-index --assume-unchanged $DIRECTORY

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

我关闭了编辑器 (Visual Studio) 并输入了常用命令:

  1. git add .
  2. git commit -m "Comment text"
  3. git push -u origin master

这对我有用。

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

这里发生的事情是你在你的根文件夹中,你想将所有 children 推送到 git repository.So 一个 git 文件是 created.And 如果您遇到无法追踪或无法追踪的文件错误,原因是您的子目录中的某些文件也有一个 git 存储库 it.You 可以从未跟踪或无法追踪的文件夹中删除 git 存储库按命令 ---->rmdir -Force -Recurse .git 此命令将删除 untracebale 或 untracked 目录中的本地 git 存储库,然后再次转到根文件夹并键入相同的命令。 重新初始化 git 存储库并完成!!!

我也遇到过这样的问题,确实很困扰我。 我通过 运行 git submodule update.

解决了

log4cplus 是您的子模块,已修改但未跟踪内容。

  • 修改内容:转到您的子模块“log4cplus”提交您修改的更改
  • 未跟踪的内容:表示您在子模块中添加了尚未开始跟踪的新文件或新文件夹,即 git 添加 。如果您想忽略未跟踪的文件,请将它们添加到 .gitignore.

现在您应该能够将提交从子模块更新到您的主或外部存储库。 请注意,删除子模块中的 .git 文件不是解决方案。