Git log & revert

While developing our software, we will make lots of commits. We will change, add and delete files and create many points of history. It should be then possible for us to visit these points in history, and perhaps reset our history to the specific points.

In order for us to view our commits we can run

$ git log

Two really helpful variations of this command are

$ git log --raw

where all modified files are shown, and

$ git log -p -- /some/file/path.ext

where we view all the modifications to a specific file in a reverse chronological order

We may also view a commit by running

$ git show <commit id>

Reverting a commit is also crucial. Imagine that we have just pushed a commit to production which is full of bugs (it happens, it has happened to everybody and it will continue to happen for as long as your software exists). We might need to revert this commit immediately, and we can by running

$ git revert <commit id>

Another way of tracking changes is git blame where one may blame a single file and view in an annotated way, each line and the corresponding commit hash where the line was introduced. Example, blaming the index file of this jekyll application:

$ git blame index.html
72ac450 (Barry Clark      2014-02-06 19:18:00 -0500  1) ---
^72ac450 (Barry Clark      2014-02-06 19:18:00 -0500  2) layout: default
^72ac450 (Barry Clark      2014-02-06 19:18:00 -0500  3) ---
^72ac450 (Barry Clark      2014-02-06 19:18:00 -0500  4)
e347e37f (Fotis Alexandrou 2015-03-24 02:15:01 +0200  5) <h1>Git Training</h1>
e347e37f (Fotis Alexandrou 2015-03-24 02:15:01 +0200  6) <p>
Written on March 6, 2015