Derric Lewis
Derric Lewis

Reputation: 1243

How to determine which files are behind origin/master in Git

When I run the command 'git status' on my work-area, I get the message show below:

# On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.

Now if I run the command 'git pull' the work-area is updated with the files that are ahead on the origin/master. The command also displays on the screen the files that are being pulled in to update my work-area.

Is there a way to determine this file list without actually running the 'git pull' command?

Upvotes: 2

Views: 2988

Answers (5)

TrongBang
TrongBang

Reputation: 967

You can use this command

git diff HEAD origin/your/feature/branch

Given you have checked out your feature branch locally and are seeing this message:

Your branch is behind 'origin/your/feature/branch' by 1 commit, and can be fast-forwarded.

This shows the difference between your local state and the remote feature branch.

Upvotes: 0

FrozenDroid
FrozenDroid

Reputation: 166

Try git fetch and git reflog.

Upvotes: -1

talves
talves

Reputation: 14353

To see what commits have been added to the upstream master, run a git log using origin/master as a filter. Will show the commits.

git fetch
git log --oneline master..origin/master

example output:
2d8ad7d fix a whole bunch of stuff
c1ee8ec updated some values

Then use the commit id to view the files of a commit.

git diff --no-commit-id --name-only -r2d8ad7d
or
git diff --stat -r2d8ad7d

Note: This example and your solution is tracking the remote branch origin/master. If you are tracking a different branch, replace that branch name in the command above.

Upvotes: 1

John Szakmeister
John Szakmeister

Reputation: 47032

git diff --stat master origin/master would do the trick.

You can also shorten it to git diff --stat HEAD @{u} if origin/master is set as the upstream branch for master.

Upvotes: 4

Makoto
Makoto

Reputation: 106440

You can use the --stat flag of git diff against the remote branch.

git diff --stat origin/master

This will show the list of files that have changed along with how many lines were removed/added. This also will not update your current branch's reference in any way.

Upvotes: 6

Related Questions