65

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
LinFelix
  • 1,026
  • 1
  • 13
  • 23
Ayush
  • 880
  • 1
  • 9
  • 21
  • 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? – Tim Biegeleisen May 04 '18 at 05:50
  • @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." – Ayush May 04 '18 at 05:55
  • 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-dirty – Ayush May 04 '18 at 06:00
  • 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. – Tim Biegeleisen May 04 '18 at 06:01
  • @TimBiegeleisen doing "git add " is making no difference to the output of "git status" for the two mentioned directories – Ayush May 04 '18 at 06:03
  • I tried "git add log4cplus" – Ayush May 04 '18 at 06:04
  • 1
    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. – Tim Biegeleisen May 04 '18 at 06:11
  • 2
    Is your question how to stage, commit and push while dealing with with a repository that is made up of `submodules`? – LinFelix May 04 '18 at 08:25
  • @TimBiegeleisen yes I think – Ayush May 04 '18 at 08:31

10 Answers10

118

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.

Kellen Stuart
  • 7,775
  • 7
  • 59
  • 82
xplorer1
  • 1,254
  • 1
  • 10
  • 13
  • 5
    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? – SimonC Mar 06 '19 at 08:08
  • 17
    @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 , 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. – xplorer1 Mar 10 '19 at 09:25
  • Acceptable and confirms my thoughts. I came to a similar conclusion. – SimonC Mar 11 '19 at 09:59
  • 3
    it can be also because you have a .git inside this folder – open-ecommerce.org Jul 04 '19 at 12:14
  • 1
    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. – xplorer1 Jul 05 '19 at 09:51
  • Hi I copy pasted my code to the local git repo and tried to push it. What I did is it wrong? – joekevinrayan96 May 30 '21 at 18:11
73

Remove .git from subfolders. This works for me.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Bishwa Timilsina
  • 1,053
  • 9
  • 11
8

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.
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Quan Truong
  • 197
  • 2
  • 11
5

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

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Taiger
  • 129
  • 1
  • 3
3

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

Kele Huang
  • 59
  • 2
1

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!!!

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.

vivek87799
  • 11
  • 1
1

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 
Lavanya
  • 11
  • 4
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

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

0x5C91
  • 3,360
  • 3
  • 31
  • 46