Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View git diff from individual parents

Say, I've been presented with a merge conflict, and I managed to fix it, but haven't marked as resolved (i.e. I haven't done git add conflicted files yet). At this point, I can do git diff and I'll be shown how the resultant file differs from each parent, in a combined diff format.

All good so far. Now I wanted to separately inspect how resultant file differs from individual parent. Sure, for a merge conflict involving 2 parents (cherry-pick, rebase etc.), I can use git diff --ours or git diff --theirs, but how do I extend this to more parents?

In other words, if I get conflict from 3 parents, is it possible to view individual diffs w.r.t each parent?

Also, my discovery of --ours and --theirs was rather serendipitous; I couldn't find their usage documented in a diff context.

like image 767
Jeenu Avatar asked Nov 12 '15 11:11

Jeenu


People also ask

How do I see my git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

How do you look at git diff of a commit?

To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit: git diff COMMIT~ COMMIT will show you the difference between that COMMIT 's ancestor and the COMMIT .

Can you git diff a specific file?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.

Why is git diff not showing?

Why do you get no git diff output before adding? Git does not treat files in the filesystem as automatically included in the version control system. You have to add things explicitly into the Git repository (as you are doing by adding the current directory with git add . ).


1 Answers

If

git diff :1:foo.txt :3:foo.txt

does not do what you want, I guess you have to do

git ls-files -u

and the use git show $sha1 > $sha1.txt to create some temporary files and compare those.

See also: Git compare "base" version with "theirs" version of a conflicted file?

like image 95
Mikko Rantalainen Avatar answered Oct 11 '22 22:10

Mikko Rantalainen