Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'git diff' doesn't show enough

I want to see the difference between the master branch and my feature branch. I have many pulls from the master to my feature branch and want to see the changes that would be added if I merged my feature into the master.

This is my situation:

-*--*--*-----*<master>   \     \     \    1--*--*--*--2--*<feature> 

My problem is git diff master feature seems to only display commit number 2. How can I see the diff that a GitHub pull request would show, which I believe is all the way to commit 1?

I noticed git cherry shows me the commits I want to see the difference for.

like image 375
codr Avatar asked Mar 10 '11 06:03

codr


People also ask

Why is git diff not showing anything?

There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.

How do I view 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.

What is git diff command?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.


2 Answers

The important thing to realize about git diff A B is that it only ever shows you the difference between the states of the tree between exactly two points in the commit graph - it doesn't care about the history. The .. and ... notations used for git diff have the following meanings:

An illustration of the different ways of specifying commits for 'git diff'

So when you run git diff master feature that's not just showing you the change introduced by the commit you've marked as 2 - the output should show the exact differences between the state of the tree committed in master and the state of the tree committed in feature. If it's not showing you the earlier changes on your feature branch, perhaps you resolved conflicts from the earlier merges from master in favour of the version in master?

As cebewee says, it may be that what you want is git log -p master..feature, since git log does care about history. The meaning of .. and ... for git log are different since they select a range of commits:

An illustration of the different ways of specifying ranges of commits for git log

Incidentally, it's often said that merging from master into a topic branch is the wrong thing to do - instead you should be rebasing, or merging your topic branch into master after it is complete. This keeps the meaning of the topic branch easily understood. The Git maintainer did a (somewhat difficult to understand) blog post about the philosophy of merging which discusses that.

like image 134
Mark Longair Avatar answered Sep 16 '22 20:09

Mark Longair


git diff master feature does not show any of the commits, but the textual difference between the commits master and feature. It sounds as if you want to see all commits from feature, which are not yet in master? In this case, try git log master..feature or git log -p master..feature, if you want to see the diffs, too.

See the section SPECIFIYING RANGES in man git-rev-parse for an explanation of the 'a..b' syntax.

like image 37
Lars Noschinski Avatar answered Sep 18 '22 20:09

Lars Noschinski