Working With Advanced Git Logs

Posted By : Shiv Pujan Maurya | 28-Jan-2018

Advanced git filtering and formatting could be very helpful in various situations. When you have big code base for any project and want to find specific details these commands might come handy. Let’s get to work
 
git log -- online: This option just displays commits with one line details of each commit.This is very helpful when you want to have a high-level overview of the project.

f7hkeeb Add files via upload
6c2f6c3  docs commented
9saad51 support mail tested
b45c56c Upload Document 

 

git  log --decorate :  This command gives the branch and tag information of each commit.

user@host$ git log --decorate
commit 784673bhzwb38740fc28f15493d2c39b (HEAD, origin/master, origin/HEAD, master)
Author: name 
commit 3902nsjhf06278740fc28f15493d2c39b (HEAD, origin/master, origin/HEAD, master)
Author: name 
Date:   Wed Sep 20 23:13:49 2017 +0530

    Add files via upload

 

git log --oneline --decorate : This command gives a better result by limiting the history to one line.

user@host$ git log  --oneline --decorate 
6d88bd3 (HEAD, origin/master, origin/HEAD, master) Add files via upload
35nccec Create UI of Forget page
494cd37 changes in api
893hd58 changes in file
c398662 changes in api
48nsa11 Discount api done
 

git log --stat : This command gives the no. of insertion and deletions done in any commit.

user@host$ git log --stat
commit 387378hd93bmndbf13eb898a90485d76408a43
Author: Puja 
Date:   Mon Aug 28 20:19:35 2017 +0530

     docs commented              |  14 ++++----

 

 

git log -p :  This option gives the actual changes done in the file.

user@host$ git log -p
commit 387378hd93bmndbf13eb898a90485d76408a43
Author: Puja 
Date:   Mon Aug 28 20:19:35 2017 +0530

Add files via upload
diff --git a/repo/deploy.sh b/repo/deploy.sh
new file mode 100644
index 0000000..e54f2ca
--- /dev/null
+++ b/repo/deploy.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+cd /home/ubuntu/dir
+mvn clean 

  

git shortlog : This command gives one liner  groups the commits by author and with first line of every commit. This could be helpful when you want overview of project. Passing git shortlog -n sorts this output by no. of commits per author.

user@host$ git shortlog
Rohit  (3):
      Added Angular2 frontend seed with angular2 bootstrap
      Implemented layout structure,configure routes and home page
      Implemented UI of signup,login & home view
Annu  (2):
       resolved conflicts in app routes
      Added mobile number verification screen
 

 

git log --graph:  This option prints the output in an ASCII graph format. This gives better results with --oneline and --decorate

user@host$ git log --graph --oneline --decorate
*   18cfac6 Merge branch 'dev' of test into uid
|\  
| * d4d53e1 Add in security config for  wallet
* | 4df62fd invested amount added in domain
|/  
*   4f4a4gff Merge branch
  
 

Custom formatting : custom formatting can be applied to logs by passing place holders. Eg %cn: commiter’s name , %h: gives hash, %cd : gives commit date.

user@host$ git log --pretty=format:"%cn work %h ondate %cd"
GitHub work f7c5eeb ondate Wed Sep 20 23:10:11 2017 +0530
abhi work dc2s6c3 ondate Mon Aug 28 20:19:35 2017 +0530
raj work b0sdc56c ondate Mon Aug 28 17:29:40 2017 +0530
 

 

Git commit filtering: we can apply multiple filters by passing arguments to git log some are as following.

user@host$ git log -5  
#gives last five commit logs

user@host$ git log --after=”2017-5-1”  
# gives logs by after requested date

user@host$ git log --after=”2017-5-1”  --before=”2017-4-4” 
#gives logs in between dates 

user@host$  git log --author=”Flask”
#gives logs by author

user@host$ git log --author=”Flask \| Stane”
#gives logs of both authors

user@host$ git log test.py 
#gives logs tets.py

user@host$ git log master..dev
#gives logs by branch
 

 

Summary: What we learnt above?

Git  logs, diff, custom formatting,log filtering, shorting, git log graph etc.

 

About Author

Author Image
Shiv Pujan Maurya

Shiv is a Redhat certified engineer with B.Tech in Computer Science & Engineering. He is passionate about new technologies specially in DevOps and Artificial intelligence.

Request for Proposal

Name is required

Comment is required

Sending message..