How to fix "modified content, untracked content" in git?
Asked Answered
A

12

73

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
Andalusite answered 4/5, 2018 at 5:47 Comment(9)
Many of these untracked files appear to be things which you would not normally want to version in Git. Have you done any development work on actual source files?Elongation
@TimBiegeleisen "cppzmq" is a library.So I haven't touched it at all. I am not sure whether I have modified any file in "logc4plus."Andalusite
The output of "git diff" is : diff --git a/fes/log4cplus b/fes/log4cplus --- a/fes/log4cplus +++ b/fes/log4cplus @@ -1 +1 @@ -Subproject commit 091c838f24e33af81e8f4baa87cab4dbe2b9775a +Subproject commit 091c838f24e33af81e8f4baa87cab4dbe2b9775a-dirty diff --git a/lib/notification/cppzmq b/lib/notification/cppzmq --- a/lib/notification/cppzmq +++ b/lib/notification/cppzmq @@ -1 +1 @@ -Subproject commit 84ab7a0fc6f8d9a1bdbc3ce42d84027dca4286d7 +Subproject commit 84ab7a0fc6f8d9a1bdbc3ce42d84027dca4286d7-dirtyAndalusite
You don't need git diff to find out which files have been modified, git status will already tell you that. Whatever files you want to track, just git add them, then commit, that's it.Elongation
@TimBiegeleisen doing "git add " is making no difference to the output of "git status" for the two mentioned directoriesAndalusite
I tried "git add log4cplus"Andalusite
If git add is not adding the file, then my guess is that this file is part of your .gitignore file. And with good reason; whoever setup those files doesn't want you adding these system files.Elongation
Is your question how to stage, commit and push while dealing with with a repository that is made up of submodules?Pickard
@TimBiegeleisen yes I thinkAndalusite
A
124

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.

Anya answered 9/10, 2018 at 13:52 Comment(6)
While this does fix the problem, it does not explain what's going wrong; why the problem occurred in the first place. It must have something to do with Git messing something up. Does anyone care to/can any elaborate on why this happens?Karachi
@SimonC. I believe it is usually caused by having more than one it repos in the same directory or subdirectory. In my own case, I had two separate git repos in two different directories. But I moved one into the other. So when I run git <command>, it sort of confuses it as to which repo to use. The above commands then tries to remove git from one of the directories and then add it back (in case you want to be pushing all to one directory). I hope my explanation is acceptable.Anya
Acceptable and confirms my thoughts. I came to a similar conclusion.Karachi
it can be also because you have a .git inside this folderOler
Yes @open-ecommerce.org. You have a folder with git initialized in it. And that folder is contained within another folder that has git initialized in it too. So they conflict. So git rm -rf --cached innerfolder to remove the tracked inner one and git add to add it back.Anya
Hi I copy pasted my code to the local git repo and tried to push it. What I did is it wrong?Pressley
P
80

Remove .git from subfolders. This works for me.

Purcell answered 3/1, 2020 at 13:11 Comment(5)
as simple as that 😍Hemato
Fine. Worked for my solution.Poorhouse
or if that subfolder has it's own repository, you can just add it to .gitignore, since the other repository keeps track of it!Cribriform
Fine. Worked for me too!Boehmenism
Simple Explanation and totally right ! . ThanksLadawnladd
P
9

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.
Polychasium answered 10/10, 2018 at 6:9 Comment(0)
S
7

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).

Sawyer answered 28/11, 2019 at 16:40 Comment(0)
W
3

I also encountered such a problem, and it indeed bothered me a lot. I solved it by running git submodule update.

Winfordwinfred answered 10/5, 2021 at 9:4 Comment(2)
The correct command is actually git submodule update, not git submodules update!Slobber
Yeah, you are right. I have rectified it.Winfordwinfred
C
2

What happening here is that you are in your root Folder Folder and You want to push all your children to git repository.So a git file is created.And if you get a untraceable or untracked file error the reason is some on your childen directories also have a git repository with it.You can delete the git repository from the untracked or untraceable folder by command ---->rmdir -Force -Recurse .git This command will delete the local git repo in your untracebale or untracked directory and once again go to your root folder and type the same command. Reinitialize the git repo and its Done!!!

Cantankerous answered 10/10, 2020 at 19:14 Comment(0)
S
2

I faced the same issue, I had a folder structure like this,

/project
  ---> /client
  ---> /server 

The client folder was untracked because it was a git repository in itself. I followed the following steps to resolve the problem

1) remove .git file from client folder
2) run the command "git rm -rf --cached client"
3) git add client
4) git push -u origin main 
Schwerin answered 19/3, 2023 at 8:4 Comment(0)
V
1

log4cplus is your submodule that has modified and untracked contents.

  • modified content: Go to your submodule "log4cplus" commit your modified changes
  • untracked contents: Says that you have added new files or new folders in your submodule that you have not yet started to track i.e., git add <newfile/newfolder>. In case you want to ignore the untracked files add them to the .gitignore.

Now you should be able to update the commits from the submodule onto your main or outer repository. Please note that deleting the .git file in your submodule is not a solution.

Vorticella answered 13/4, 2022 at 0:35 Comment(0)
L
0

i solved the problem by moving in sub folder which what not tracking and run

these command: git add . git commit -m "my commit"

then back to main folder and run again these command

Literal answered 24/11, 2022 at 17:16 Comment(0)
S
0
  1. Go to your submodule: cd your_submodule
  2. Clean it: git clean -fdx .

That's it. No need to manually remove any sensitive files or re-download anything.

Speed answered 2/11, 2023 at 9:54 Comment(0)
O
0

Remove .git from folders which are not being added into git stage. This is the simplest way

If you can't find it or hidden do the following. In Finder, open your Macintosh HD folder. Press Command + Shift + . (period) to make the hidden files appear.

-->> not working for me

git rm -rf --cached

Outwit answered 10/6 at 14:47 Comment(0)
U
-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.

Ungotten answered 4/12, 2019 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.