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.
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.
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?
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:
Or more simply, just use HEAD:
Assuming you're on local branch master
, which is tracking origin/master
:
git diff --stat origin/master..
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
Source: Stackoverflow.com