Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable -m in git

Tags:

git

bash

I am trying to train myself to write better commit messages, so I have created an entry in my ~/.gitconfig

[commit]
    template = ~/.gitmessage.txt

The conundrum is that I nearly always use:

git commit -m "Message here"

and sometimes:

git commit -am "Message here"

How can I prevent myself from using the -m flag, so that my template will be presented and I will be reminded to use it?

I don't need to absolutely enforce this in the project, but I would like to wean myself off of "-m".

Ubuntu/Bash is my environment.

like image 440
Daniel Bower Avatar asked Mar 03 '14 21:03

Daniel Bower


People also ask

What does sslVerify false do?

sslVerify false to disable SSL verification if you're working with a checked out repository already.

How do I stop git push?

The trick to prevent accidentally pushing in-development changes to the wrong environment is to use the git command for changing remote's URL. By adding the --push flag to the command, only the push URL is manipulated. So it is still possible to pull from that remote.


2 Answers

Put this in your .bashrc:

git() {
  for arg
  do
    if [[ $arg == -m* || $arg == -[^-]*m* ]]
    then
      annoy_me
      return 1
    fi
  done
  command git "$@"
}
annoy_me() { 
  echo "Stop using -m, $USER!" 
  echo "You are now in time out."
  settings=$(stty -g)        
  stty raw
  sleep 15
  stty "$settings"
}

annoy_me here waits 15 seconds and is not killable from that terminal.

You can replace it by whatever you consider suitably annoying, such as sl or mplayer -volume 100 Spice_Girls_Wannabe.mp3 < /dev/null &> /dev/null &

like image 51
that other guy Avatar answered Sep 30 '22 18:09

that other guy


You can write a shell script called git as well and put it into your PATH before the real git. Inside it, you just check the args for -m, if present scoff at yourself, if not call the real git binary.

See this question for an example how to forward the args.

like image 42
C. Ramseyer Avatar answered Sep 30 '22 18:09

C. Ramseyer