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

I confess that sometimes I use git commit -a

when I shouldn't. It was getting a reflex about half the time, often when I think I am working in separate repositories, but I am actually working in a lot more that will affect directories far and wide.

Is it possible to specify a parameter .git/config

that will cause the error -a

to trigger the error?

+3


source to share


3 answers


Is there a .git / config parameter I can specify that will result in the -a error for the error?

Not that I know.



You will need a git wrapper that will check the arguments (" commit

", " -a

", ...), and on a specific command, "commit -a" will throw an error.

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

+1


source


Thanks to VonC, I hacked into the function I got 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;
}

      

+2


source


No, there is nothing in the git config that will do this. However there is a solution and git is hooks.

Git hooks are scripts that are executed before or after a git command is executed - for example, there is a hook that doesn't remove your commit if there is no commit message. So you can write a costum hook for your needs, which falls when the commit is sloppy.

However, personally I would not mind, but rather show an additional hint (for example, "Are you sure?" Y / N). Think about it, do you really want to block functionality forever?

More information: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

Good luck!

+1


source







All Articles