git rebase -i-为什么更改提交哈希? [英] git rebase -i -- why is it changing commit hashes?

查看:239
本文介绍了git rebase -i-为什么更改提交哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我或多或少都熟悉重新定标的工作原理,但是直到最近,我通常只是做一个git rebase -i HEAD~20,并修改了需要修改的地方.

So I'm more or less familiar with how rebasing works, but up until recently I usually just did a git rebase -i HEAD~20, and modified whatever needed to be modified.

得知这将修改所有20次提交的哈希值,我感到很惊讶,即使我唯一要做的就是压倒最后两个提交.

I was surprised to learn that this will modify the hashes of all 20 commits, even if the only action I take is to squash the last two.

我不确定是什么原因导致其他18次提交的哈希值发生变化,因为父母双方,内容都没有变化……或者是吗?也许是时间戳记?

I'm not sure what causes the hash change for the other 18 commits though, since neither their parents, neither their contents change... Or does it? Maybe a timestamp?

还有办法防止这种情况吗?

Also is there a way to prevent that?

推荐答案

这将修改所有20次提交的哈希值,即使我唯一要做的就是压倒最后两次提交的哈希值.

this will modify the hashes of all 20 commits, even if the only action I take is to squash the last two.

如果用最后两个"来表示历史中最近的两次提交,那么不会,不会.

If by "the last two" you mean the most recent two commits in the history, then no, it won't.

请具体,显示您正在查看的实际证据,待办事项清单和执行的清单.表征对于未共享的上下文来说太过不可靠易受攻击.

Please be concrete, show the actual evidence you're looking at, the todo list you got and the one you executed. Characterizations are far too unreliablevulnerable to unshared context.

例如,据我所知,当我压缩最后两个提交时会发生什么:

Here for instance is what happens when I squash the last two commits, as I understand it:

$ git log --oneline --reverse @{u}..
00f53a2 echo >master6
afcef3e echo >master7
1f55c48 echo >master8
c3197a0 echo >master9
d30bb35 (HEAD -> master) echo >master10
$ GIT_SEQUENCE_EDITOR='sed -i 5s/pick/squash/' git rebase -i
[detached HEAD 16dc80d] echo >master9
 Date: Mon Feb 5 09:25:55 2018 -0800
 2 files changed, 2 insertions(+)
 create mode 100644 master10
 create mode 100644 master9
Successfully rebased and updated refs/heads/master.
$ git log --oneline --reverse @{u}..
00f53a2 echo >master6
afcef3e echo >master7
1f55c48 echo >master8
16dc80d (HEAD -> master) echo >master9
$ 

您可以看到最后两个提交已被压缩在一起,所有未更改历史记录的提交的ID保持不变.

you can see that the last two commits have been squashed together, the id's of all the commits whose history hasn't changed are left untouched.

这篇关于git rebase -i-为什么更改提交哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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