Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git prevent amends to pushed commits

Tags:

git

Is it possible to have git check the remote branch in the prepare-commit-msg hook and see if the current commit is an amend, and if so, abort the commit? That way it makes sure that you can not amend a commit that you already pushed, which would be handy.

like image 204
FalcoGer Avatar asked Sep 01 '25 11:09

FalcoGer


1 Answers

There is no way to prevent someone doing git commit --amend on their own machine.

You can however prevent people from force pushing git push --force and rewriting the repository history. This is done with a server side hook e.g. see Github's Blocking force pushes to a repository.

like image 143
Karol Dowbecki Avatar answered Sep 04 '25 00:09

Karol Dowbecki