git commit --amend-在不进行任何更改的情况下更改提交哈希 [英] git commit --amend - commit hash is changed when no changes are made

查看:264
本文介绍了git commit --amend-在不进行任何更改的情况下更改提交哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意对我的理解进行一些更正,但是我不确定为什么会发生这种情况.

I open for some correction of my understanding of this, but I am not sure why this happens.

使用git时,我了解到,如果我对文件进行更改然后提交,则会得到新的哈希值,因为文件已更改.

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.

我对git commit --amend的理解是我可以更改上一次提交.

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.

但是当我不进行任何更改而只是保存并退出编辑器时(我可能已经改变了主意,需要更改),为什么哈希会更改? 我所有的文件和所有内容都相同,但是我已经保存了.当我的git log提交时间没有更改时,它只是在日志中出现两次,同时带有相同的时间,相同的消息,相同的文件,但提交哈希不同.

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??

推荐答案

Git哈希是使用许多项目计算的,包括作者姓名/日期,提交名称/日期提交消息,树和父SHA等.修改提交时, commit 的名称和日期会更新. (除非您将其他格式选项传递给git log,否则通常看不到提交名称和日期.)因为已经更新了该内容,所以在修改提交时,提交哈希将发生变化.

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.

这篇关于git commit --amend-在不进行任何更改的情况下更改提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆