How to make git ignore changes to submodules by default

后端 未结 5 1841
无人共我
无人共我 2021-01-05 12:11

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

[submodule \"actionbarsherlock\"]
path = actionbarsherlock
url = git://github.com/JakeWh         


        
相关标签:
5条回答
  • 2021-01-05 12:46

    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.

    0 讨论(0)
  • 2021-01-05 12:49

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

    0 讨论(0)
  • 2021-01-05 12:49

    Do you mean this?

    git config --global core.ignore dirty

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

    0 讨论(0)
  • 2021-01-05 12:50

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

    0 讨论(0)
  • 2021-01-05 12:50

    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.

    0 讨论(0)
提交回复
热议问题