简体   繁体   中英

Git diff on rewriting history

I am curious to know about Git diff in this situation, i could not find in Git docs

Assume on branch A , i have three commits as
Branch A: Commit 3 <-- Commit 2 <-- Commit 1

Commit 3 is latest on branch.

  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

Branch A: Commit 3' <-- Commit 1
Commit 3' includes commit 3 and commit 2 after rebasing.

Now if I run the command git diff commit3 commit3' will it work ? If yes, then why and what changes will it show in diff?

  1. If we delete the commit 3 and just keep commit 2 as latest master after rebasing. Then what git diff commit 3 commit 2 will show?

Note: here commit 3 has been deleted, how git will track this if found diff?

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.

This differs from "applying a change", such as cherry-pick would do, for instance. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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