Why doesn't git amend warn you when there's nothing to amend?

git, git-amend, git-commit

Solution

The committer date (`%ci`) keeps being reset, even if the commit author date (`%ai`) remains the same: For instance, if I commit --amend -no-edit the last commit on the Git repo, the author date remains unchanged, but I just created a new commit: replacing the old one with the same content, but a different commit date:

P:\git\git>git show -s --format="%ci" e0d6576639261beefb40afa52696d02f16c490ed
2012-12-11 03:42:23 +0100  <== just now

P:\git\git>git show -s --format="%ai" e0d6576639261beefb40afa52696d02f16c490ed
2012-12-07 14:18:55 -0800  <== original date when the author did commit

So any amend will result in a different SHA1.

From the Pro-Book:

- The author is the person who originally wrote the work,

- whereas the committer is the person who last applied the work.

A `commit --amend` will always recreate a new commit, if only because the committer date is changing.

Problem

I oftentimes make the mistake of making a change to a file right after a commit, then running `git commit --amend` followed by a quick `git push -f origin master` The issue, obviously, is that I never ran `git add foo.md`. So my amend didn't actually amend any of my committed code. Question is: Why doesn't git warn you when amending a commit with no changes? Better yet, why does it even complete successfully? Is it merely behaving like a "touch" in changing the timestamp of a given commit?

Original source