There is even a possibility to set the ignore mode for every added submodule within the .gitmodules file.
Just today I encountered this problem and immediately wrote an article in my blog about it after finding a solution: How to ignore changes in git submodules
The gist of it:
Once you added a submodule there will be a file named
.gitmodules
in the root of your repository
Just add one line to that .gitmodules
file:
[submodule "bundle/fugitive"]
path = bundle/fugitive
url = git://github.com/tpope/vim-fugitive.git
ignore = dirty
There are two kinds of change notices you can suppress.
The first is untracked content
which happens when you make changes to your submodule but have not yet committed those. The parent repository notices these and git status
reports it accordingly:
modified: modules/media (untracked content)
You can suppress these with :
[submodule "modules/media"]
path = modules/media
url = [email protected]:user/media.git
ignore = dirty
However, once you commit those changes, the parent repository will once again take notice and report them accordingly:
modified: modules/media (new commits)
If you want to suppress these too, you need to ignore all
changes
[submodule "modules/media"]
path = modules/media
url = [email protected]:user/media.git
ignore = all
Update: See (and upvote) nilshaldenwang's answer regarding the possibility to add to the .gitmodules
file a config parameter for ignoring dirty state of a given submodule.
ignore = dirty
So git 1.7.2 is out and includes the --ignore-submodules
option for status
.
From git help status
:
--ignore-submodules[=<when>] Ignore changes to submodules when looking for changes. <when> can be either "untracked", "dirty" or "all", which is the default. When "untracked" is used submodules are not considered dirty when they only contain untracked content (but they are still scanned for modified content). Using "dirty" ignores all changes to the work tree of submodules, only changes to the commits stored in the superproject are shown (this was the behavior before 1.7.0). Using "all" hides all changes to submodules (and suppresses the output of submodule summaries when the config option status.submodulesummary is set).
The value that I want is dirty
.
git status --ignore-submodules=dirty
I use an alias because I'm lazy:
alias gst='git status --ignore-submodules=dirty'
As you mention, the patch git submodule: ignore dirty submodules for summary and status is in the making.
Also announced in the Git 1.7.2-rc2 release:
Git v1.7.2 Release Notes (draft)
================================
Updates since v1.7.1
--------------------
"
git status
" learned "--ignore-submodules
" option.
Meaning:
git config --global diff.ignoreSubmodules dirty
Regarding this as an option is not exactly the approach chosen for now:
After this series I am planning to add a config option '
ignore
' to.gitmodules
, which can be set for each submodule to either "all", "dirty", "untracked" or "none" (the default).
"git diff
" and "git status
" will use that config value for each submodule.
Using "--ignore-submodule
" overrides this default (and the new parameter "none" will be added there to able to override the config settings).
And to avoid having to do "
git submdule sync
" every time that option changes, I would like to search for it in.git/config
first.
If it is not found there, it will be taken from.gitmodules
, if present.So users can override the setting but if they don't, upstream can change it easily (e.g. when a submodules
.gitignore
has been updated so that "ignore=untracked
" is no longer necessary anymore it can be removed).
Also switching branches will have an effect instantly if the 'ignore
' entry in.gitmodules
is different between branches.
Another approach to make git status (or any git command) to ignore a particular submodule is available with Git 2.13 (Q2 2017):
git config submodule.<name>.active false
See more at "Ignore new commits for git submodule".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With