2

I often require to do a make clean / make distclean before I do a git add . since I do not want to include binary and other stuffs.

I know I can add some name / pattern in to .gitignore but that's not very productive and flexible. Another solution is to create a bash file but that requires an additional file in my repository that I don't want.

Is there any pre-add configuration that allows me to run script before the actual git add execution ?

w00d
  • 5,416
  • 12
  • 53
  • 85
  • I don't know what you mean by "productive", but `.gitignore` is very flexible. – Carl Norum Oct 16 '13 at 16:52
  • for example, the name of the binary may change, or when I add new binary I have to add that into .gitignore too, what's the best way ? – w00d Oct 16 '13 at 16:57
  • Modify `gitignore` at the same time you make the change that changes the name of (or introduces) the binary. – chepner Oct 16 '13 at 17:01
  • Add `grep -q "^$@$$" .gitignore || echo $@ >>.gitignore` to your makefile's recipe for binaries. – jthill Oct 17 '13 at 13:51
  • maybe in pre-commit script you could do what you need and run git add . at the end so commit would work fine with your changes –  Jun 16 '15 at 08:45

1 Answers1

3

The earliest hook Git provides is the pre-commit hook. At this point, git add would already have been run, but you could write a pre-commit hook that ensures certain files / file extensions have not been added. However, this will require the same amount of maintenance as a gitignore file would.

Ayush
  • 41,754
  • 51
  • 164
  • 239
  • thanks! could you be clearer about the pre-commit hook ? Is it possible to run a script using that hook ? I can do something like, "git reset; make clean; git add." – w00d Oct 16 '13 at 17:07
  • Yes, you can run a script as well as allow or disallow the commit. You can read about Git hooks [here](http://git-scm.com/book/en/Customizing-Git-Git-Hooks). – Ayush Oct 16 '13 at 17:17