Thread (1 message) 1 message, 1 author, 2016-06-15

Re: How to prevent empty git commit --amend

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:03:29

Matthieu Moy [off-list ref] writes:
Ivo Anjo [off-list ref] writes:
quoted
Is there a way to prevent a *git commit --amend** with nothing to
commit from working?
If not, I would like to suggest that this feature would be very helpful :)
I don't know any way to let Git do the check for you, but 

git diff --staged --quiet || git commit --amend

should do it. You can alias it like

[alias]
	amend = !git diff --staged --quiet || git commit --amend

and then use "git amend".
That would not let you say "git amend Makefile", no?

	!sh -c 'git diff --cached --quiet "$@" || git commit --amend "$@"' -

or something, perhaps?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help