View Unpushed Changes in Git

When focus shifts to other projects. It might happen that some repository sits around for a while without being worked on. And if getting your forked repository synced isn’t a big enough problem. It might contain some unpushed changes. So this happened the other day at the office.

$ git status

# On branch master
# Your branch is ahead of ‘origin/master’ by 16 commits.
nothing to commit (working directory clean)

Doing a simpel push would resolve the problem. But what if some changes are not needed anymore. Or some other spec changes that allow for some further inspection. So it might be a good idea to inspect the changes before we push them to remote. And thankfully git makes this quite easy. By diffing the HEAD against remote master.

$ git diff origin/master..HEAD

diff –git a/path/library/init.php b/path/library/init.php
index 0c5ae45..50a2060 100644
— a/path/library/init.php
+++ b/path/library/init.php
@@ -8,13 +8,6 @@
* directory structure.

-function FOO_library_autoloader( $classname )
- $classfile = str_replace(“_”, “/”, $classname) . ‘.php’;
- if (file_exists(LIBRARY . $classfile))
- require_once(LIBRARY. $classfile);

And voila. A diff of all unpushed changes. This also works for upstream repository’s. But the code has to fetched first. So before running the diff command. Do this

$ git fetch upstream master
$ git diff upstream/master..HEAD
comments powered by Disqus