git-apply或git-am应该使用相同的散列吗? [英] Should git-apply or git-am come up with the same hash?

查看:130
本文介绍了git-apply或git-am应该使用相同的散列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我错过了一些东西。我的印象是,git使用SHA-1哈希提交标识符意味着可以确定从其他人那里获得的补丁没有被修改过。



在我的机器上进行这个测试(显然名称和电子邮件已更改):

  cd dogcatcher 
dogcatcher> git log
commit 926f347567a9da6f7692aca0e23d13f094d9e3a6
作者:Joe User< joe@test.com>
日期:星期六12月17日15:28:55 2011 -0600

第3次分支提交

提交11e8055aa5e8f0d323c48b4f691adced7a8a9762
作者:Joe用户< joe @ test.com>
日期:Sat Dec 17 15:10:44 2011 -0600

第二分支提交
$ b $提交23deb7093a8565479092ef84142a0e2e7282d213
作者:Joe用户< joe @ test.com>

dogcatcher> git format-patch 23de(格式化包含自23de以来所有内容的补丁)

dogcatcher> cd ..
〜> cp -r dogcatcher catcatcher
cd catcatcher

catcatcher> git reset --hard 23de(将HEAD重置为23de)
catcatcher> git am 00 *(应用两个补丁文件)
catcatcher> git log

commit 2548980811d1875971ce1a018df98374950e0059
作者:Joe User< joe@test.com>
日期:星期六12月17日15:28:55 2011 -0600

第3次分支提交

提交7d651d05344ba6e2cd18d8e24c0c350d0c7dec66
作者:Joe用户< joe @ test.com>
日期:Sat Dec 17 15:10:44 2011 -0600

第二分支提交
$ b $提交23deb7093a8565479092ef84142a0e2e7282d213
作者:Joe用户< joe @ test.com>

正如您所看到的,最后两个提交中的哈希是不同的,它们是由补丁创建的。现在,也许这是有道理的。当然,由补丁创建的文件的时间戳是不同的。 (我不确定散列中包含哪些信息)



然而,如果是这种情况,我如何验证我刚刚应用的补丁包含相同的代码?我怎么知道发给我补丁文件的人没有做出恶意更改?



或者我犯了一个错误,导致了不同的哈希,并且我完成了它正确,我会拿出相同的哈希?

解决方案

默认情况下, git am 将提交者日期设置为当前时间。您可以使用 - committer-date-is-author-date 标志来避免这种情况,尽管它仍然可以将您设置为提交者(实际上它可能会) 。你可以通过使用 git log --format = fuller 来验证它,它也显示提交者信息。


I think I'm missing something. I was under the impression that git's usage of a SHA-1 hash commit identifier meant that one could be certain that patch obtained from someone else for that commit had not been altered.

Take this test I did on my machine (name and email changed, obviously):

cd dogcatcher
dogcatcher> git log
commit 926f347567a9da6f7692aca0e23d13f094d9e3a6
Author: Joe User <joe@test.com>
Date:   Sat Dec 17 15:28:55 2011 -0600

    3rd branch commit

commit 11e8055aa5e8f0d323c48b4f691adced7a8a9762
Author: Joe User <joe@test.com>
Date:   Sat Dec 17 15:10:44 2011 -0600

    second branch commit

commit 23deb7093a8565479092ef84142a0e2e7282d213
Author: Joe User <joe@test.com>

dogcatcher> git format-patch 23de  (format a patch containing everything since 23de)

dogcatcher> cd ..
~> cp -r dogcatcher catcatcher
cd catcatcher

catcatcher> git reset --hard 23de  (reset HEAD to 23de)
catcatcher> git am 00* (apply the two patch files)
catcatcher> git log

commit 2548980811d1875971ce1a018df98374950e0059
Author: Joe User <joe@test.com>
Date:   Sat Dec 17 15:28:55 2011 -0600

    3rd branch commit

commit 7d651d05344ba6e2cd18d8e24c0c350d0c7dec66
Author: Joe User <joe@test.com>
Date:   Sat Dec 17 15:10:44 2011 -0600

    second branch commit

commit 23deb7093a8565479092ef84142a0e2e7282d213
Author: Joe User <joe@test.com>

As you can see, the hashes are different on the last two commits, which were created by the patch. Now, perhaps that makes sense. Certainly the timestamps on the files created by the patch were different. (I'm not sure what set of information is included in the hash)

However, if that's the case, how can I verify that the patches I just applied contain exactly the same code? How do I know the person that sent me the patch files didn't make nefarious changes?

Or did I make a mistake that caused the different hash, and had I done it correctly, I would have come out with the same hash?

解决方案

By default, git am sets the Committer Date to the current time. You can use the --committer-date-is-author-date flag to avoid that, though it may still set you as the committer (in fact, it probably will). You can verify this by using git log --format=fuller instead which shows the Committer information as well.

这篇关于git-apply或git-am应该使用相同的散列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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