Git Notes based on Pro Git Book
git reflog
Show history of where the HEAD and branch refs have been in local repository. Information stored as reflog is strictly local.
af7725c HEAD@{0}: checkout: moving from testBranch to master
662b3ca HEAD@{1}: checkout: moving from master to testBranch
af7725c HEAD@{2}: reset: moving to af7725c
662b3ca HEAD@{3}: reset: moving to HEAD^
af7725c HEAD@{4}: commit: Commit D
662b3ca HEAD@{5}: commit: Commit C
f46d0d9 HEAD@{6}: commit: Commit B
bbb7387 HEAD@{7}: commit (initial): Commit A
          
git rev-parse master
Show commit pointed to by ref
af7725caab2d197f07c72f6d9a4814d5d9ce9e53
          
git show bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Show details of a commit SHA along with diff
commit bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A

diff --git a/testfile.txt b/testfile.txt
new file mode 100644
index 0000000..557db03
--- /dev/null
+++ b/testfile.txt
@@ -0,0 +1 @@
+Hello World
        
git show bbb738
Show details of a abbreviated commit SHA along with diff
commit bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A

diff --git a/testfile.txt b/testfile.txt
new file mode 100644
index 0000000..557db03
--- /dev/null
+++ b/testfile.txt
@@ -0,0 +1 @@
+Hello World
        
git show master
Show commit details along with diff pointed to by a ref
commit bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A

diff --git a/testfile.txt b/testfile.txt
new file mode 100644
index 0000000..557db03
--- /dev/null
+++ b/testfile.txt
@@ -0,0 +1 @@
+Hello World
        
git show HEAD@{7}
Show details of a commit along with diff pointed to by a reference in reflog
commit bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A

diff --git a/testfile.txt b/testfile.txt
new file mode 100644
index 0000000..557db03
--- /dev/null
+++ b/testfile.txt
@@ -0,0 +1 @@
+Hello World
        
git show master@{3.hour.41.minute.ago}
Show details of a commit where master was 3 hour 41 minutes ago. Other examples include ref@{yesterday}
commit f46d0d9949274bba7f797a5b63bc004f291905b4
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:03 2016 +0530

    Commit B

diff --git a/testfile.txt b/testfile.txt
index 557db03..bc1c618 100644
--- a/testfile.txt
+++ b/testfile.txt
@@ -1 +1,2 @@
 Hello World
+ABC
        
git log
Prints details of all commits reachable from HEAD
commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D

commit 662b3caf91bbb8faf56ef7262615a8828b381be1
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:16 2016 +0530

    Commit C

commit f46d0d9949274bba7f797a5b63bc004f291905b4
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:03 2016 +0530

    Commit B

commit bbb738746b14e8e4ac09a443e9ac1c931ad61d07
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A
         
git log --abbrev-commit
Prints details of all commits reachable from HEAD but it prints SHA of commit in abbreviated form
commit af7725c
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D

commit 662b3ca
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:16 2016 +0530

    Commit C

commit f46d0d9
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:01:03 2016 +0530

    Commit B

commit bbb7387
Author: Nitin Nizhawan <abc@example.com>
Date:   Sat Feb 27 21:00:29 2016 +0530

    Commit A
            
git log --oneline
Print abbreviated SHA and commit msg summary in one line
af7725c Commit D
662b3ca Commit C
f46d0d9 Commit B
bbb7387 Commit A
           
git log -g
Print reflog formatted as git log
commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Reflog: HEAD@{0} (Nitin Nizhawan )
Reflog message: checkout: moving from testBranch to master
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D

commit 662b3caf91bbb8faf56ef7262615a8828b381be1
Reflog: HEAD@{1} (Nitin Nizhawan )
Reflog message: checkout: moving from master to testBranch
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:16 2016 +0530

    Commit C

commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Reflog: HEAD@{2} (Nitin Nizhawan )
Reflog message: reset: moving to af7725c
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D

commit 662b3caf91bbb8faf56ef7262615a8828b381be1
Reflog: HEAD@{3} (Nitin Nizhawan )
Reflog message: reset: moving to HEAD^
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:16 2016 +0530

    Commit C

commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Reflog: HEAD@{4} (Nitin Nizhawan )
Reflog message: commit: Commit D
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D
           
git log -g master
Print reflog in the format of git log for only master branch. Shows commits master has pointed to in you local workspace.
commit 20e9855e2b90ee6580c3b8db250dae0d9b18cff1
Reflog: master@{0} (Nitin Nizhawan )
Reflog message: commit: Commit E
Author: Nitin Nizhawan 
Date:   Sun Feb 28 11:54:30 2016 +0530

    Commit E

commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Reflog: master@{1} (Nitin Nizhawan )
Reflog message: reset: moving to af7725c
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D

commit 662b3caf91bbb8faf56ef7262615a8828b381be1
Reflog: master@{2} (Nitin Nizhawan )
Reflog message: reset: moving to HEAD^
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:16 2016 +0530

    Commit C

commit af7725caab2d197f07c72f6d9a4814d5d9ce9e53
Reflog: master@{3} (Nitin Nizhawan )
Reflog message: commit: Commit D
Author: Nitin Nizhawan 
Date:   Sat Feb 27 21:01:30 2016 +0530

    Commit D
           
  • Single Selection

pre-commit
Run first. It is used to inspect snapshot. Can be used to check if tests are run, code styling, documentation was applied.

        
prepare-commit-msg
Run before the commit message editor is fired but after the default msg is created Params
  • path to file containing msg
  • type of commit
  • sha of commit if it is an amended commit

        
commit-msg
Can be used to validate final commit msg and abort if it's not correct. Takes path to file containing msg as param

        
post-commit
Can be used for notification of commit. Does not take any parameter.

        
applypatch-msg
First hook run after git am command. Takes one parameter that is path to file containing msg

        
pre-applypatch
Run after patch is applied but before commit is created. Can be used to run tests, inspect working tree. Can be used to abort commit by returning non zero value

        
post-applypatch
Runs after commit is made. Can be used to notify of the commit

        
pre-rebase
Run before you rebase anything. Can be use to halt git rebase. Can be used to disallow rebasing any commit which have been pushed already

        
post-rewrite
Run after commits are rewritten by either git rebase or git commit --amend but not git filter-branch. Param is the command which triggered rewrite. And list of commits as stdin . This can be used to setup working directory after rewrite.

        
post-checkout
Runs after checkout. Can be used to setup working directory, like moving large files , auto generating documentation etc.

        
post-merge
Runs after a successful merge

        
pre-push
Runs after remote refs have been updated but no data has been transmitted yet. It receives name and location of remote as params and list of to be updated refs as stdin

        
pre-auto-gc
Runs before GC takes place and can be used to notify or abort GC based on some criteria.

        
pre-recieve
Runs when data from push is received . can be used to reject push completely

        
update
Similar to pre-recieve but is executed once for each branch. Can be used to reject push for branches selectively

        
post-recieve
Runs after entire process is complete. Can be used to notify usees or other systems. Client waits for this this script to return before disconnecting. So, should not do long blocking tasks.