0

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 i.e. 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?

John Byro
  • 674
  • 3
  • 13
  • `git diff` compares trees, so yes it will work. Try it out with a minimalistic set of files in a test repo, you'll see it for yourself. – Romain Valeri Oct 22 '21 at 16:00

1 Answers1

0

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.

Obsidian
  • 3,719
  • 8
  • 17
  • 30