For example I commit some files, the next day some more files, and so on. After some days I want to view all my committed files and view their difference with the remote repo. Note that I have not pushed anything. I just want to verify that if I push some thing then it will go to the remote repo as I expect.
-
6Git doesn't push `files`. It pushes `commits`. – Noufal Ibrahim Oct 19 '10 at 10:37
-
what command will be use to remove local commits, those i have not pushed? – Usman Ali Oct 19 '10 at 11:47
-
git checkout
. This will restore your file to the original state. – tom Oct 19 '10 at 12:19 -
`Git checkout
` will revert files to the HEAD revision. It will not "uncommit" changes. The functionality is similar to "revert" in svn and others. If you want to "remove local commits", you'll have to do a `git reset` to the appropriate commit. – Noufal Ibrahim Oct 20 '10 at 07:54
8 Answers
Assuming you're on local branch master
, which is tracking origin/master
:
git diff --stat origin/master..

- 30,042
- 15
- 70
- 103
-
1
-
2@MartínNieva the two dots indicate a range, between the thing that was named and whatever HEAD is. I said "assuming you're on local branch master", so HEAD is master. So this will show you the difference between origin/master and master. You could also write this as `origin/master..master`. – bstpierre Oct 11 '21 at 19:55
-
this answer will show just the files . if you want to see the details you should use "git diff HEAD origin/master " as @N 1.1 answered – zohee May 14 '23 at 08:59
Here you'll find your answer:
Using Git how do I find changes between local and remote
For the lazy:
- Use "git log origin..HEAD"
- Use "git fetch" followed by "git log HEAD..origin". You can cherry-pick individual commits using the listed commit ids.
The above assumes, of course, that "origin" is the name of your remote tracking branch (which it is if you've used clone with default options).

- 10,870
- 5
- 35
- 75

- 8,189
- 12
- 51
- 70
-
2Doesn't answer the question - "view all my committed files and view their difference with the remote repo". – user9645 Jul 22 '21 at 11:31
-
2
The push
command has a -n
/--dry-run
option which will compute what needs to be pushed but not actually do it. Does that work for you?

- 71,383
- 13
- 135
- 169
-
but how do we know that what are the changes that done with this push? – xkeshav Aug 11 '17 at 19:26
-
It will show you what all commits would be pushed and you can then do a git diff between the relevants heads to find out what has changed. – Noufal Ibrahim Aug 12 '17 at 05:26
-
when I run `git status` ; it display my branch is ahead of 2 commits along with local file changes, which I'll commit later. so I just do `git push -n` and run `git diff` but it shows only the changes which are in local. – xkeshav Aug 12 '17 at 05:59
-
IF your current branch is `master` and your remote branch is `origin/master`, then `git diff origin/master...master` will give you the differences in those commtis. – Noufal Ibrahim Aug 12 '17 at 10:12
I'm not great with Git, but this is what I do. This does not necessarily compare with the remote repo, but you can modify the git diff
with the appropriate commit hash from the remote.
Say you made one commit that you haven't pushed...
First find the last two commits...
git log -2
This shows the last commit first, and descends from there...
[jason:~/git/my_project] git log -2
commit ea7937edc8b10
Author: xyz
Date: Wed Jul 27 14:06:41 2016 -0500
Made a change in July
commit 52f9bf7956f0
Author: xyz
Date: Tue Jun 14 14:29:52 2016 -0500
Made a change in June
Now just use the two commit hashes (which I abbreviated) to run a diff:
git diff 52f9bf7956f0 ea7937edc8b10

- 1,836
- 2
- 17
- 33
-
Thanks this was helpful. One thing I think makes it nice is to add --name-only after the diff so you only see the file names. git diff
--name-only
git diff HEAD origin/master
Where origin
is the remote repository and master
is the default branch where you will push. Also, do a git fetch
before the diff
so that you are not diffing against a stale origin/master.
P.S. I am also new to git, so in case the above is wrong, please rectify.

- 12,418
- 6
- 43
- 61
-
2I would like to point out that your syntax will show "+" for what was in the remote and "-" for what is in the local. That seems backward to me (a matter of taste)--I want a "+" to show what I've committed locally and a "-" to show what's on the remote. So I use: git diff origin/master HEAD – dnuttle May 05 '14 at 13:44
-
Seemed reversed to me... I was getting "deletions" instead of "insertions" & vice-versa. I used `git diff origin/master HEAD` and it was what I expected. – user9645 Jul 22 '21 at 11:38
The previous answers are all good, but they all show origin/master. These days, following the best practices, I rarely work directly on a master branch, let alone from origin repo.
So if you are like me who work in a branch, here are tips:
- Say you are already on a branch. If not, git checkout that branch
- git log # to show a list of commit such as x08d46ffb1369e603c46ae96, You need only the latest commit which comes first.
- git show --name-only x08d46ffb1369e603c46ae96 # to show the files commited
- git show x08d46ffb1369e603c46ae96 # show the detail diff of each changed file
Or more simply, just use HEAD:
- git show --name-only HEAD # to show a list of files committed
- git show HEAD # to show the detail diff.

- 701
- 7
- 6
git diff @{u}..
That's the diff between current commit to your upstream branch. And if you only care about modified file names, then
git diff @{u}.. --name-only

- 21
- 3
In IntelliJ UI, on the Git toolbar located upper right you may click the up-pointing green arrow 'Push' and will then get a modal dialog which shows the files that were already committed but not pushed yet.
Within the dialog, it's possible to inspect files and either push them or abort.

- 181
- 1
- 7