Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git ignore changes to submodules by default

Since gitmodules were introduced in Git, I like to add them like so:

[submodule "actionbarsherlock"]
path = actionbarsherlock
url = git://github.com/JakeWharton/ActionBarSherlock.git
ignore = dirty

The important part here is ignore = dirty.

When using the git submodule add command, I'm forced to add this line by myself in the .gitmodules file.

How can I make this the default behavior for every git submodule add I'll make in the futur?

I know about the submodule.<name>.ignore configuration, but how to apply it to all by default?

like image 395
shkschneider Avatar asked Oct 31 '12 14:10

shkschneider


2 Answers

Note that even if there were such a config, git 2.0.1 (June 25th, 2014) would still show you a submodule which has been staged.

See commit 1d2f393 by Jens Lehmann (jlehmann)

Currently setting submodule.<name>.ignore and/or diff.ignoreSubmodules to "all" suppresses all output of submodule changes for the diff family, status and commit.

For status and commit this is really confusing, as it even when the user chooses to record a new commit for an ignored submodule by adding it manually this change won't show up under the to-be-committed changes.
To add insult to injury, a later "git commit" will error out with "nothing to commit" when only ignored submodules are staged.

Fix that by making wt_status always print staged submodule changes, no matter what ignore settings are configured.
The only exception is when the user explicitly uses the "--ignore-submodules=all" command line option, in that case the submodule output is still suppressed.
This also makes "git commit" work again when only modifications of ignored submodules are staged, as that command uses the "commitable" member of the wt_status struct to determine if staged changes are present.

See also commit c215d3d for the git commit part.

like image 73
VonC Avatar answered Sep 21 '22 10:09

VonC


So to close this, no, there is not default option for it (sadly).

like image 20
shkschneider Avatar answered Sep 24 '22 10:09

shkschneider