10

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?

4
  • Don't know if there's a way to do this by default, but you could easily add an alias or script to do it for you. Commented Oct 31, 2012 at 17:22
  • I don't see how to do that by alias. And as for script, I just hoped git had a default option for it Commented Oct 31, 2012 at 17:25
  • Git will treat as an alias any script in $PATH that starts with git-<command> as git <command>. You could just write a shell script that accepts the submodules name, adds it, then issues the submodule.<name>.ignore configuration and just call it git supersubmodule or something. Commented Oct 31, 2012 at 17:38
  • @Christopher I know I can do that, so they really are no git options for it? Please post an answer with your last comment if so. Commented Oct 31, 2012 at 17:39

6 Answers 6

7

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


To add insult to injury, a later "git commit" will error out with "nothing to commit" when only ignored submodules are staged.

Actually... with Git 2.42 (Q3 2023), even when diff.ignoreSubmodules tells us to ignore submodule changes, "git commit"(man) with an index that already records changes to submodules should include the submodule changes in the resulting commit, but it did not.
And this has been fixed!

See commit 5768478 (14 Jun 2023) by Josip Sokcevic (sokac).
(Merged by Junio C Hamano -- gitster -- in commit 4ee088d, 23 Jun 2023)

diff-lib: honor override_submodule_config flag bit

Signed-off-by: Josip Sokcevic

When diff.ignoreSubmodules = all is set and submodule commits are manually staged (e.g. via git-update-index), git-commit should record the commit with updated submodules.

index_differs_from is called from prepare_to_commit with flags set to override_submodule_config = 1.
index_differs_from then merges the default diff flags and passed flags.

When diff.ignoreSubmodules is set to "all", flags ends up having both override_submodule_config and ignore_submodules set to 1. This results in git-commit ignoring staged commits.

This patch restores original flags.ignore_submodule if flags.override_submodule_config is set.

Sign up to request clarification or add additional context in comments.

1 Comment

Same deal for git-gui: github.com/git/git/commit/…
3

Today I found out that can use git config to change the .gitmodules file, and therefore can add the ignore dirty flag without going into the file and adding the line by hand:

git config -f .gitmodules submodule.actionbarsherlock.ignore dirty 

In my case, I was able to automate the two steps in a script with that command.

Comments

2

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

1 Comment

This still appears to be true on git v2.7.0.
2
[submodule "book"] path = book url = https://[email protected]/user/repo.git ignore = all 

or use

git config -f .gitmodules submodule.tests.ignore all 

1 Comment

While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
1

I'm not sure about a default option. Were it a binary state (ignore or not), you could get traction with:

diff.ignoreSubmodules Sets the default value of --ignore-submodules. Note that this affects only git diff Porcelain, and not lower level diff commands such as git diff-files. git checkout also honors this setting when reporting uncommitted changes. 

But as you're using dirty I'm not sure there's a way to set a default. Regardless, you could do this with a git alias in your $PATH. Write a script that accepts the submodule as an argument and set the proper dirty configuration value, then add that script to your $PATH. Call it git-<command> and it'll be available as git <command>.

2 Comments

Ok, I know options for diff and status, but would like a better thing. A script is a posible option.
This is a good candidate for the git list. THey could give you a definite answer, and if that answer is "no", a patch might be proposed.
-1

Do you mean this?

git config --global core.ignore dirty

which writes the preference to your ~/.gitconfig file.

3 Comments

I don't think it works. At least it's not working for me (git 1.8.5).
@brianclements What version supports this option?
I use git 1.9.1 on Ubuntu 14.04. But on second revisit, I think this doesn't work for me either. But then again, alerting me to "new commits" and "untracked content" for my submodules is the behavior I wanted anyway perhaps I misunderstood OP's question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.