How to view the committed files you have not pushed yet?
GitGithubGit Problem Overview
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 Solutions
Solution 1 - Git
Assuming you're on local branch master
, which is tracking origin/master
:
git diff --stat origin/master..
Solution 2 - Git
Here you'll find your answer:
For the lazy:
> 1. Use "git log origin..HEAD" > 2. 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).
Solution 3 - Git
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?
Solution 4 - Git
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
Solution 5 - Git
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.
Solution 6 - Git
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.