4

we are a group of developers working on the same set of files. I want to make sure that no one does a git commit -a -m or git commit -am

The developers including me have this bad habbit of git commit -am/ -a -m and we have a lot of conf files specific to the machine that get committed everytime. I could ask us all to use --assume-unchanged but I want to make the developers not be able to use -a flag at all

Can I hack somehow to achieve this.?

Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96
  • 4
    I can't answer the question, but if the intent is specifically to guard against committing conf files, then perhaps creating a `.gitignore` may help. – chipschipschips Sep 27 '12 at 09:41

2 Answers2

5

I would recommend you to solve this problem differently:

  1. use a .gitignore file to specifically exclude files which must not be committed or
  2. use a pre-commit hook to automatically reject commits which look like they were made with -a.

When you insist on disabling the -a flag: well, git is open source. Finding and disabling the code which reads the -a command line parameter and recompiling shouldn't be that hard. But that would mean you would have to do it again whenever a new version of git is released, so I would really advise against that.

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • Even I am against rewriting git. I will try to learn to write precommit hook. ANy good resources? – Ranjith Ramachandra Sep 27 '12 at 11:44
  • @RanjithR You can start by looking at the `.git/hooks/*.sample` files in any git repository. But I don't know whether `-a` doesn't stage all modified files _before_ calling that hook – Tobias Kienzler Sep 27 '12 at 11:50
  • 2
    I think a .gitignore file would be the better solution. It would still allow people to save time by using -a, but prevent them from committing any machine-specific files. – Philipp Sep 27 '12 at 11:54
  • The problem is .gitignore will completely ignore that file. Sometimes we add things to the conf file and we will need to commit them. Then everyone is informed to take a backup and we merge them with care. – Ranjith Ramachandra Sep 27 '12 at 17:35
  • @RanjithR So does your acceptance mean you made a pre-commit hook? If so please edit it into the answer for others to see – Tobias Kienzler Oct 09 '12 at 06:20
  • No. I initially decided to use pre commit hook. Hence I accepted the answer. But the problem was solved after a strong management session and now everyone uses git commit -m aliased as gcm. – Ranjith Ramachandra Oct 09 '12 at 10:29
2

You can write a wrapper git script that checks whether the command is commit and has the -a flag set. Then you can either drop that and pass everything else on to the actual git, or prompt "Bad User! Bad!". Put that script in the path before the actual git path or create an alias for your gitwrap.

@PiotrZierhoffer found this:

An example for that is here: Disable -m in git

Community
  • 1
  • 1
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221