简体   繁体   English

关于重写历史的 Git diff

[英]Git diff on rewriting history

I am curious to know about Git diff in this situation, i could not find in Git docs我很想知道在这种情况下 Git diff,我在 Git 文档中找不到

Assume on branch A , i have three commits as假设在分支 A 上,我有三个提交
Branch A: Commit 3 <-- Commit 2 <-- Commit 1

Commit 3 is latest on branch. Commit 3是最新的分支。

  1. Now if we re-write the commit history ie rebase the recent Head~2 commits and and squash them into one, then branch looks like现在,如果我们重写提交历史,即重新设置最近的Head~2提交并将它们压缩为一个,那么分支看起来像

Branch A: Commit 3' <-- Commit 1
Commit 3' includes commit 3 and commit 2 after rebasing. Commit 3'包括commit 3和rebase后的commit 2。

Now if I run the command git diff commit3 commit3' will it work ?现在,如果我运行命令git diff commit3 commit3'会起作用吗? If yes, then why and what changes will it show in diff?如果是,那么它为什么会在 diff 中显示什么变化?

  1. If we delete the commit 3 and just keep commit 2 as latest master after rebasing.如果我们删除commit 3并在 rebase 后将commit 2保留为最新的 master。 Then what git diff commit 3 commit 2 will show?那么git diff commit 3 commit 2会显示什么?

Note: here commit 3 has been deleted, how git will track this if found diff?注意:这里提交 3 已被删除,如果发现差异,git 将如何跟踪?

It will work because every commit is actually a snapshot of the current state of your working repository, regardless of what brought this repository into this particular state.它会起作用,因为每次提交实际上是您工作存储库当前状态的快照,无论是什么使此存储库进入此特定状态。 So you may compare any revision to any one else.因此,您可以将任何修订版与其他任何修订版进行比较。

If you simply rebased to coalesce your commits, you should get no difference between commit3 and commit3' since their final states are the same.如果您只是简单地重新定位以合并您的提交,则commit3commit3'之间应该没有区别,因为它们的最终状态是相同的。

This differs from "applying a change", such as cherry-pick would do, for instance.这与“应用更改”不同,例如,cherry-pick 会这样做。 In this latter case, changeset is first obtained by comparing the selected commit with its parent one, then the diff's result is applied to the current working directory.在后一种情况下,首先通过将所选提交与其父提交进行比较来获得变更集,然后将差异结果应用于当前工作目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM