179

Possible Duplicate:
Using Git how do I find modified files between local and remote

How can I see incoming commits in git? Or even better, see what I just git fetch/git pulled?

Edit: To clarify the question: someone tells me that, to get some fixes, I should pull from their repository. My goal is to see what their changes are before I accept them. git pull automatically merges, which is not what I want. git fetch will grab them without merging, but I'm unsure how to view what exactly I just pulled in. The reason for the original phrasing is that I normally use Mercurial, where the command would be hg incoming <repo name here>—a command for which git seems to lack an analog.

Community
  • 1
  • 1
Benjamin Pollack
  • 27,594
  • 16
  • 81
  • 105

5 Answers5

214

incoming isn't quite a direct mapping in git because you can (and I often do) have multiple repos you're pulling from, and each repo has multiple branches.

If there were an equivalent of hg's incoming command, it'd probably be this:

git fetch && git log ..origin/master

That is, "go grab all of the stuff from the upstream, and then compare my current branch against the upstream master branch."

Similarly, outgoing would be this:

git fetch && git log origin/master..

In practice, I just type those manually (even though I created an alias for one of them) because it's easy to have lots of local branches tracking and being tracked by lots of remote branches and have no trouble keeping it together.

Dustin
  • 89,080
  • 21
  • 111
  • 133
  • 8
    Also you might want to use `git diff --stat origin/master` to see the diffstat that `git pull` shows after succesfull merge. – Jakub Narębski Aug 27 '09 at 10:03
  • 3
    Thank you for this answer @Dustin! Could I ask, I don't quite understand the magic behind `log ..origin/master` what do the dots signify? – gideon Mar 18 '12 at 12:24
  • It's not so much magic, it's shown in the synopsis for `git log` and described as the second option in the options section of [the man page](http://schacon.github.com/git/git-log.html) which then leads to the [gitrevisions](http://schacon.github.com/git/gitrevisions.html) doc which goes into much more detail. – Dustin Mar 23 '12 at 22:27
  • 41
    More generically, if you're not on the master branch, use `git log ..@{u}` to see the commits that are on the upstream remote tracking branch of your current local branch. – sschuberth Oct 05 '12 at 06:49
  • @gideon that command is actually `git log HEAD..origin/master`. the dots signify from left to right. – David T. Nov 17 '14 at 08:20
  • @sschuberth Great comment, but how can one do this for the **origin** remote tracking branch, instead of the "upstream" remote? Can you reference any docs? I have an SO post [here](http://stackoverflow.com/questions/31155103/how-to-reference-remote-repositories-in-a-git-alias) that details my question... – modulitos Jul 01 '15 at 07:34
  • @Lucas I've added an answer to your other question. – sschuberth Jul 01 '15 at 07:45
93

You may also be interested in git whatchanged which gives a good overview of changes that have been made in some range of commits.

If you want to review what you're about to pull, do a git fetch first, which only updates local tracking branches for the remote repository (and not any of your branches), and then use any command that shows you the new commits that you're about to pull. For example:

git whatchanged ..origin

This is shorthand for showing the commits between "the common ancestor of wherever I am now and origin" through "origin".

Gregg Lind
  • 20,690
  • 15
  • 67
  • 81
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    ahh, I like this better than using git log – JP Silvashy Aug 26 '09 at 19:39
  • 5
    From git manpage: > New users are encouraged to use git-log[1] instead. The whatchanged command is essentially the same as git-log[1] but defaults to show the raw format diff output and to skip merges. > The command is kept primarily for historical reasons; fingers of many people who learned Git long before git log was invented by reading Linux kernel mailing list are trained to type it. – mja Oct 23 '18 at 20:00
18

You may want to examine the difference between two repositories. Assumed you have a local branch 'master' and a remote-tracking branch 'origin/master', where other people commit their code, you can get different stats about the differences of the two branches:

git diff --summary master origin/master

git diff --stat master origin/master

git diff --numstat master origin/master

git diff --dirstat master origin/master

git diff --shortstat master origin/master

git diff --name-only master origin/master

git diff master origin/master
Netzpirat
  • 5,481
  • 1
  • 22
  • 21
8

When someone tells you to pull, they will give you the repo URL and a branch (default being master).

I'd just do

git fetch URL branch

followed by one (in decreasing order of preference):

# note 3 dots in next 3 commands
gitk HEAD...FETCH_HEAD
    # shows all commits on both sides since the "fork" point
gitk --cherry-pick HEAD...FETCH_HEAD
    # as above but skips identical patches so you really see the differences
git log --graph --boundary --left-right --cherry-pick --decorate HEAD...FETCH_HEAD
    # I have a nice alias for this; it's the text mode eqvt of the above

I also use "tig" sometimes, but this specific usecase (seeing both sides) is not well served by tig.

However, if you bring it down to two dots (which may match your actual question more closely, though I still prefer the 3 dot versions), you can do

tig HEAD..FETCH_HEAD

Here are the aliases for convenience:

incoming = !sh -c 'git fetch && git log --graph --boundary --left-right --cherry-pick --decorate HEAD..FETCH_HEAD'
outgoing = !sh -c 'git fetch && git log --graph --boundary --left-right --cherry-pick --decorate FETCH_HEAD..HEAD'
Trass3r
  • 5,858
  • 2
  • 30
  • 45
Sitaram
  • 91
  • 1
  • 1
1

There is no such thing as "incoming commits" users commit locally and push them. I would open up gitx or gitk(that comes with git) and check out what the repos looks like... I think that will give you a clear view.

use: gitk --all to see.

JP Silvashy
  • 46,977
  • 48
  • 149
  • 227