How to get rid of Git submodules untracked status?
Asked Answered
T

12

194

I can't seem to get rid of untracked content in Git's submodules. Running git status yields:

# On branch master
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#    modified:   bundle/snipmate (untracked content)
#    modified:   bundle/surround (untracked content)
#    modified:   bundle/trailing-whitespace (untracked content)
#    modified:   bundle/zencoding (untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

Adding the --ignore-submodules parameter hides these messages; but I wonder if there's a way to get rid of this dirt in a more suitable, core-ish, manner.

Triphylite answered 26/2, 2011 at 12:2 Comment(2)
This answer: https://mcmap.net/q/14043/-gitignore-files-added-inside-git-submodules evokes more option.Pleinair
Does this answer your question? Git: can I suppress listing of 'modified content'/dirty submodule entries in status, diff, etc?Rainier
R
118

Since the git status reports untracked content, the actual way to have a clean status would be to go into each one of those submodules and:

  • add and commit the untracked contents,
  • or reference the untracked contents in a .gitignore specific to each module.
  • or you can add the same ignored content to the submodule's .git/info/exclude, as peci1 reports in the comments.
  • or add dirty to the submodule specification, as mentioned in ezraspectre's answer (upvoted).

    git config -f .gitmodules submodule.<path>.ignore untracked
    
  • or add a global .gitignore file (often ~/.gitignore-global). Like for example .DS_Store or in my case Carthage/Build as reported by Marián Černý in the comments. See .gitginore man page:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

Ron answered 26/2, 2011 at 12:30 Comment(8)
+1, I was about ready to scream until I found this...then realizing a .DS_Store file had been automatically created (by OS X) in one of my submodules, preventing me from committing the main project. Arg! Time to update .gitignore...Antigua
Using Xcode, I've also found it useful to add *.xcuserdatad to the .gitignore-global file. This prevents git from trying to track local Xcode preferences.Cholla
If you don't have push rights to the submodule then you cannot share your changes to the submodule with other users of the parent repo. @quincyglenn's solution seems to work in such a case.Elli
@DrewNoakes I agree. It is just that I prefer dealing with dirty changes (by adding them to a .gitignore or adding them to source control), but not by "hiding" them with a local config option.Ron
@VonC, either answer makes sense depending upon the situation and preference. I wanted to highlight the distinction here as a reference to others. BTW thanks for your many answers regarding Git here on SO -- you've helped me out many a time.Elli
You can even do without both commiting and creating a .gitignore (which itself becomes untracked). Open the submodule's .git/info/exclude and add the ignore lines there (it works like a .gitignore, but is not part of the shared repository).Quintanilla
@peci1 good point. I have included your comment in the answer for more visibility.Ron
Sometimes you can also add those untracked contents into a global gitignore file (often ~/.gitignore-global). Like for example .DS_Store or in my case Carthage/Build.Flamingo
L
184

I found this blog post to work overall. By adding the ignore = dirty option to each one of the entries in the .gitmodules file.

[submodule "zen-coding-gedit3"]
    path = zen-coding-gedit3
    url = git://github.com/leafac/zen-coding-gedit3.git
    ignore = dirty
Lapith answered 8/9, 2012 at 15:38 Comment(3)
My preferred solution, as it's easily automated.Sandhi
Worth mentioning that ignore = untracked also exists, and shows modified tracked files, but not untracked files. It'd be nice if there was a global setting for this for all submodules...Crepitate
Unsuprisingly, after almost a decade, the blog post link is dead. :)Stopped
R
118

Since the git status reports untracked content, the actual way to have a clean status would be to go into each one of those submodules and:

  • add and commit the untracked contents,
  • or reference the untracked contents in a .gitignore specific to each module.
  • or you can add the same ignored content to the submodule's .git/info/exclude, as peci1 reports in the comments.
  • or add dirty to the submodule specification, as mentioned in ezraspectre's answer (upvoted).

    git config -f .gitmodules submodule.<path>.ignore untracked
    
  • or add a global .gitignore file (often ~/.gitignore-global). Like for example .DS_Store or in my case Carthage/Build as reported by Marián Černý in the comments. See .gitginore man page:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

Ron answered 26/2, 2011 at 12:30 Comment(8)
+1, I was about ready to scream until I found this...then realizing a .DS_Store file had been automatically created (by OS X) in one of my submodules, preventing me from committing the main project. Arg! Time to update .gitignore...Antigua
Using Xcode, I've also found it useful to add *.xcuserdatad to the .gitignore-global file. This prevents git from trying to track local Xcode preferences.Cholla
If you don't have push rights to the submodule then you cannot share your changes to the submodule with other users of the parent repo. @quincyglenn's solution seems to work in such a case.Elli
@DrewNoakes I agree. It is just that I prefer dealing with dirty changes (by adding them to a .gitignore or adding them to source control), but not by "hiding" them with a local config option.Ron
@VonC, either answer makes sense depending upon the situation and preference. I wanted to highlight the distinction here as a reference to others. BTW thanks for your many answers regarding Git here on SO -- you've helped me out many a time.Elli
You can even do without both commiting and creating a .gitignore (which itself becomes untracked). Open the submodule's .git/info/exclude and add the ignore lines there (it works like a .gitignore, but is not part of the shared repository).Quintanilla
@peci1 good point. I have included your comment in the answer for more visibility.Ron
Sometimes you can also add those untracked contents into a global gitignore file (often ~/.gitignore-global). Like for example .DS_Store or in my case Carthage/Build.Flamingo
A
21

You can also go to each submodule dir and act as a separated git. For example:

cd my/project/submodule
git status

... /gets the list of modified files/

git add .  //to add all of them to commit into submodule
git commit -m "message to your submodule repo"

you can also update your remote submodule repo with

git submodule update

after all

Anamorphosis answered 4/6, 2012 at 21:0 Comment(2)
You probably don't want to do git add . without reviewing the modified files. Most of the time, the changes that were made are the added .DS_Store files - this should probably be caught by your .gitignore, as zourtney mentioned in the first comment to the answer.Fogged
In case you actually didn't want to update the submodules and want to revert to the original state, you might want to run git submodule update --force.Godfree
U
13

This worked out just fine for me:

git update-index --skip-worktree <path>

If it doesn't work with the pathname, try the file name. Let me know if this worked for you too.

Ubangishari answered 7/9, 2018 at 15:8 Comment(1)
that works but I dont understand the underlying problem.Bonner
Z
5

It could be due to the detached HEAD in your submodule branch. If this is the case, go into your submodule path (e.g.: ./bundle/snipmate), then rungit checkout master.

Zygoma answered 3/11, 2013 at 5:14 Comment(1)
But I do not want a master, only looking for a specific commit.Balbriggan
E
3

This probably happens when you have another .git [hidden folder] inside the particular folder..

modified: ./../.. (modified content, untracked content)

make sure your sub-directory does not contains this .git folder.

If That is the case the issue can be resolved by deleting the .git folder manually from the sub directory.

Exsiccate answered 1/2, 2019 at 6:20 Comment(0)
G
2

I got stuck on this issue yesterday, in a project which had close to 12 submodules.

git status was showing output.

# On branch master
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   proj1 (untracked content)
#   modified:   proj1 (modified content, untracked content)
#   ...

To resolve the untracked content error, I had to remove the untracked files from all submodules (all were *.pyc, *.pyo files generated by python) using a .gitignore.

To resolve the other, I had to run git submodule update which updated each of the submodules.

Genevieve answered 11/2, 2015 at 18:38 Comment(0)
D
1

In my situation I clone modules as a starting point for a new module in my ZF2 environment. What this does is put its own .git folder into the directory.

Solution in this case is to delete the .git folder (you will likely need to show hidden files to view it).

Donnydonnybrook answered 5/8, 2015 at 10:21 Comment(0)
E
1

I prefer to use SourceTree, so the solution for me was to open the submodule repo in SourceTree which shows me list of all untracked files. I then group selected them all then used "Remove".

I was able to do this because I knew all the untracked files weren't actually needed.

Embay answered 8/5, 2019 at 8:39 Comment(0)
M
0

If this is a temporary issue, you can go into the submodule folder and run git reset HEAD --hard but you will lose all your changes inside of the submodule.

Microphotograph answered 9/12, 2014 at 15:16 Comment(0)
S
0

In my experience, for MacOS, this can appear because ._ files were created: In that case: try dot_clean .

Sanfordsanfourd answered 3/5, 2021 at 16:26 Comment(0)
R
-5

Just delete the .git folder in the subfolders.

Reflex answered 19/6, 2022 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.