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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50167969/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:16:30  来源:igfitidea点击:

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

gitgit-submodules

提问by Ayush

The objective is to commit a git branch. The output of "git status" for the branch is:

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

The directory structure looks like this:

目录结构如下所示:

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

I read an answer of to a similar question here:

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

How to track untracked content?,

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

and couldn't understand it completely. Also the logc4plus/.gitmodules contains this:

并且无法完全理解。logc4plus/.gitmodules 还包含以下内容:

[submodule "threadpool"]

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

[submodule "catch"]

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

回答by xplorer1

What I did was to run:

我所做的是运行:

git rm -rf --cached myuntrackedfolder

This tells git to forget about it (since it was being tracked formally).

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

Then I used:

然后我用:

git add myuntrackedfolder 

to add it and I was good to go.

添加它,我很高兴去。

回答by QuantumQuan

Solution involves removing .git/ from the directories with the "modified content, untracked content" label, removing the --cached filed from those directories, and then running git addon those directories once again.

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

Step-by-step solution:

分步解决方案:

  1. Remove .git/ from log4cplus and ../lib/notification/cppzmq.
  2. From parent directory from where you initialized your git repository, run the command: git rm -rf --cached log4cplus/ && git rm -rf --cached ../lib/notifications/cppzmq
  3. Add and commit the directories to your branch again.
  4. Push to your branch.
  1. 从 log4cplus 和 ../lib/notification/cppzmq 中删除 .git/。
  2. 从初始化 git 存储库的父目录中,运行命令: git rm -rf --cached log4cplus/ && git rm -rf --cached ../lib/notifications/cppzmq
  3. 再次添加目录并将其提交到您的分支。
  4. 推送到您的分支。

Happy coding.

快乐编码。

回答by Bishwa Timilsina

Remove .git from subfolders. That's works for me.

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

回答by Taiger

For some reason these separate repos have altered files. There are a couple ways to deal with it, depending what they actually are.

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

You can navigate into each repo and see what files are changed. Then you can commit, make a new branch, or get rid of the changes.

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

If these repos are seperate projects that you want to track but not mess with, you can make your parent repo simply ignore changes in these submodules with:

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

git update-index --assume-unchanged $DIRECTORY

git update-index --assume-unchanged $DIRECTORY

(where $DIRECTORY is the submodule you want to ignore changes to)

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

回答by Sara Benloulou

I have closed the editor (Visual Studio) and I typed the usual commands:

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

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

This worked for me.

这对我有用。