I open for some correction of my understanding of this, but I am not sure why this happens.
When using git, I understand that if I make a change to a file and then commit it I get a new hash because the file has changed.
My understanding of git commit --amend
is that I can make changes to the last commit.
Now I can understand that if I change the commit message, the hash will change.
But when I do not make any changes and just save and exit out of the editor (I may have changed my mind on needing a change) why does the hash change?
All my files and everything is the same, but I have saved it. When I of a git log
the time of the commit hasn't changed, it just appears twice in the log with the same time, the same message, same files except a different commit hash.
Why does it change if no alterations have been done??
If you amend the commit message, or the files in a commit, this will change the git hash.
The git commit –amend command lets you modify your last commit. You can change your log message and the files that appear in the commit. The old commit is replaced with a new commit which means that when you amend your old commit it will no longer be visible in the project history.
Git Rebase could update the hash of a commit mentioned in the message of another commit, if that hash changes during rebase as well. 1.
You can start your build without making any modifications to the project by pushing an empty commit.
Git hashes are calculated using a number of items, including the author name/date, commit name/date commit message, tree, and parent SHA, among others. When you amend a commit, the commit name and date are updated. (You generally don't see the commit name and date unless you pass additional formatting options to git log
.) Because that has been updated, the commit hash will change when a commit is amended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With