How can I see incoming commits in git?

GitDvcs

Git Problem Overview


> 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.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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".

Solution 3 - Git

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

Solution 4 - Git

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'

Solution 5 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBenjamin PollackView Question on Stackoverflow
Solution 1 - GitDustinView Answer on Stackoverflow
Solution 2 - GitGreg HewgillView Answer on Stackoverflow
Solution 3 - GitNetzpiratView Answer on Stackoverflow
Solution 4 - GitSitaramView Answer on Stackoverflow
Solution 5 - GitJP SilvashyView Answer on Stackoverflow