Naitree
Naitree

Reputation: 1148

On merging, Is there a way to show diffs between working tree and stage 2/3 of index respectivly?

During a merge where conflicts is involved, (if I understand this correctly) for files labeled "both modified" by git status, we can display diffs between working tree and stage 0/2/3 of index combined via

git diff -c

where (quoting from gitrevisions(7))

During a merge, stage 1 is the common ancestor, stage 2 is the target branch’s version (typically the current branch), and stage 3 is the version from the branch which is being merged.

But how do we display diffs between working tree and either side of merge (not both)? In other words, if there is a file A.txt labeled "both modified", how can we display the differences between the working-tree version and stage-2 version (or stage-3 version) of it (but not both of it)?

Upvotes: 1

Views: 39

Answers (1)

ephemient
ephemient

Reputation: 204768

git diff :2:path path
git diff :3:path path

This syntax is documented in man git-rev-parse:

:<n>:<path>, e.g. :0:README, :README

A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the index at the given path. A missing stage number (and the colon that follows it) names a stage 0 entry. During a merge, stage 1 is the common ancestor, stage 2 is the target branch’s version (typically the current branch), and stage 3 is the version from the branch which is being merged.

Upvotes: 1

Related Questions