Is there any option in git to reject my commit if I try to commit specific files which I don't want to commit at any cost unless I give approval deliberately.
-
https://stackoverflow.com/search?q=%5Bgit%5D+prevent+committing+a+file – phd Dec 19 '18 at 10:23
1 Answers
That depends on how much effort you want to go to and how much you care about deliberately working around this.
In the simplest case, you can put the file in the gitignore, and by default Git won't list it in git status
or add it in git add
unless you explicitly mention it.
If you want more warning than this, you want git hooks. If you want to do this on the client side, so git commit
fails, you need to make a pre-commit hook; you can get around this with git commit --no-verify
, but unless you explicitly say that it can prevent you from committing. I don't remember if this will always run on rebasing but I think not, so be careful if you care about that.
If you want this to run server-side, so git push
fails, you want a pre-receive hook, and you'll need to figure out how to install that on your server. This should b harder to get around on the client because it's the server doing the rejecting, but that means that if you want to be able to get around that it's harder.

- 7,223
- 2
- 26
- 41
-
Thank you for your answer. I will look into those suggestions you have given. – Veera Aravind Dec 19 '18 at 09:37