Why does the SHA-1 hash of my latest commit change even if I don't make any changes to the commit (message, files) after running git commit --amend
?
Say I run the following at the command line.
cd ~/Desktop
mkdir test_amend
cd test_amend
git init
echo 'foo' > test.txt
git add test.txt
git commit -m 'initial commit'
Then, invoking
git log --pretty=oneline --abbrev-commit
prints the following message:
b96a901 initial commit
I then do
git commit --amend
but I change my mind and decide not to change anything in the last commit. In other words, I leave the files, directories, and message of the last commit untouched (I just save the message file and close my editor).
Then, I do
git log --pretty=oneline --abbrev-commit
one more time, I see that the hash of the commit has changed:
3ce92dc initial commit
What causes the hash to change? Does it have to do with the time stamp of the commit?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…