Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop myself from using 'git commit -a'?

Tags:

git

I confess that I sometimes use git commit -a when I should not. It's gotten to be reflex about half the time, often when I think I'm working in separate repositories - but I'm actually working in a much larger one that will affect directories far and wide.

Is there a .git/config setting I can specify that will cause the -a flag to throw an error?

like image 766
Tom Ritter Avatar asked Aug 22 '26 05:08

Tom Ritter


2 Answers

Thanks to VonC, I hacked up a function I stuck in my rc file:

git() {
    if [[ ($1 == "add") || ($1 == "stage") || ($1 == "commit") ]]; then
        if [[ $@ == *-a* ]]; then
            echo "Don't use 'git $1 -a'.";
        else
            command git "$@";
        fi
    else
        command git "$@";
    fi;
}
like image 104
Tom Ritter Avatar answered Aug 26 '26 16:08

Tom Ritter


Is there a .git/config setting I can specify that will cause the -a flag to throw an error?

Not that I know of.

You would need a wrapper for git which would check the arguments ("commit", "-a", ...), and on the specific command "commit -a" would throw an error.

Jubobs' script (mentioned in the comment above) is a good example of such a wrapper.

like image 30
VonC Avatar answered Aug 26 '26 15:08

VonC