top of page

Git Log

The Git Log command is used to view the git repository's commit logs. This utility has primarily been used to review or read the committed changelog. "Git Log" has multiple options to view these logs in various formats and sequences.


Let's understand each of these in very simple terms.


  • Default git log

The "git log" command's default output displays the commit ID, which is unique within the git repository, the author's name, the date on which the author committed the changes, and then a list of the files and folders that have changed. The default output of the git logs is displayed in descending order based on the commit date and time.

[root@siddhesh MyProject1]# git log
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py

commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore
.......
Output Truncated
[root@siddhesh MyProject1]#

  • Limit the number of commits to output

The git log command by default displays all commits, which is inconvenient when you only want to see the last few commit logs. In this case, you can restrict the git log output to the last x commits. The output below shows that we are only printing the last two commit logs using "git log -2"

[root@siddhesh MyProject1]# git log -2
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py

commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore
[root@siddhesh MyProject1]# 

  • Git Log By Date

Git log by date allows us to view commit logs sequentially. which includes git log date ranges after, before, and in between.

After Date :

[root@siddhesh MyProject1]# git log --after="2023-02-07"
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py
[root@siddhesh MyProject1]# 

After & Before Date :

[root@siddhesh MyProject1]# git log --after="2023-02-02" --before="2023-02-07"
commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore

commit b9b016e351c9d70b962c21148efea3f81e0ae02d
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:30:23 2023 +0000

    added production.log to track production  log
[root@siddhesh MyProject1]# 

Since Week :

[root@siddhesh MyProject1]# git log  --since="2 weeks ago"
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000


    new index file added & modified myscript3.py
[root@siddhesh MyProject1]# 

  • Git Log By Author

Git log Limit the output of the commits to those whose author/committer header lines match the given pattern.

[root@siddhesh MyProject1]# git log --author=siddhesh -2
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py

commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore
[root@siddhesh MyProject1]# 

  • Git Log By Commit Message

Git log display commits whose log messages match the specified pattern. When we want to search a commit using its comment, this option is very helpful.

[root@siddhesh MyProject1]# git log --grep='exclude'
commit b3aaee0f2c173aa096699037a1ea5ca59459c02f
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:00:54 2023 +0000

    added .gitignore file to exclude unwanted files
[root@siddhesh MyProject1]# 

  • Git Log By Commit Range

Git log display just commits within the given revision range. The revision range defaults to HEAD if not specified. Here the references can be committed id, author etc... The .. operator and the ref names for the start commit and end commit in the range can be used to achieve this.


[root@siddhesh MyProject1]# git log b3aaee0f2c173..HEAD
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py

commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore

commit b9b016e351c9d70b962c21148efea3f81e0ae02d
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:30:23 2023 +0000

    added production.log to track production  log
[root@siddhesh MyProject1]# 

  • Git Log By File Name

The Git log shows only the commits that affect one or more files specifically.

[root@siddhesh MyProject1]# git log -- .gitignore
commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore

commit b9b016e351c9d70b962c21148efea3f81e0ae02d
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:30:23 2023 +0000

    added production.log to track production  log

commit b3aaee0f2c173aa096699037a1ea5ca59459c02f
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:00:54 2023 +0000

    added .gitignore file to exclude unwanted files
[root@siddhesh MyProject1]# 

  • Git Log One Line

All git logs can be seen in one line with a brief description in git log. which displays the commit message and the first 7 characters of the commit ID.

[root@siddhesh MyProject1]# git log --oneline
a1d864a new index file added & modified myscript3.py
acdbc46 added myscript4.py in .gitignore
b9b016e added production.log to track production  log
b3aaee0 added .gitignore file to exclude unwanted files
b6ee142 added new script myscript4
589f5a7 Newly Added Script Of Python
[root@siddhesh MyProject1]#

  • Git Log Stats

Git log stats is a very useful option that generates a diff state. This displays the files that each commit changed, along with the number of lines that were added or removed. A useful summary line that lists the total number of modified files and lines is also provided.

[root@siddhesh MyProject1]# git log --stat -2
commit a1d864af66e11d821f3d3ccd41a9f46a53bad1bf
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Thu Feb 9 17:41:27 2023 +0000

    new index file added & modified myscript3.py

 index.php    | 0
 myscript3.py | 1 +
 2 files changed, 1 insertion(+)

commit acdbc46685d420f3f8cef3944a0405a90fd93f99
Author: Siddhesh Kadam <siddhesh@builddevops.com>
Date:   Tue Feb 7 10:48:06 2023 +0000

    added myscript4.py in .gitignore

 .gitignore   | 1 +
 myscript4.py | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
[root@siddhesh MyProject1]#

bottom of page