How to fix “modified content, untracked content” in git?

白昼怎懂夜的黑 提交于 2020-05-24 14:33:47

问题


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

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:

[submodule "threadpool"]

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

[submodule "catch"]

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

回答1:


What I did was to run:

git rm -rf --cached myuntrackedfolder

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

Then I used:

git add myuntrackedfolder 

to add it and I was good to go.




回答2:


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 add on those directories once again.

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.

Happy coding.




回答3:


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




回答4:


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:

git update-index --assume-unchanged $DIRECTORY

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




回答5:


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

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

This worked for me.



来源:https://stackoverflow.com/questions/50167969/how-to-fix-modified-content-untracked-content-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!