git-log useful options - Walking Techie

Blog about Java programming, Design Pattern, and Data Structure.

Sunday, August 23, 2020

git-log useful options

What does git log do?

The git log command display all the commits history in a repository.

By default, the command displays for each commits:

  • Secure Hash Algorithm (SHA)
  • author
  • date
  • commit message

Git log options

You can customize the information provided by git-log by passing the options.

--oneline

   $ git log --oneline

The --oneline option causes git log to display each commit in one line

  • The first seven characters of SHA
  • The commit message
8fc4335 first commit
09cca7e Initial commit
  

--patch or -p

   $ git log --patch

or, the shorter version

   $ git log -p

The --patch option causes git log to display

  • Commit id, Author, Date, and commit message.
  • The files have been modified, addition/deletion in files.
  • The specific changes that happened in this commit. Like addition and deletion of changes.
  • Line number where addition/deletion happened.

You can see something like below, when you run git log --patch

Author: Santosh 
Date:   Sun Aug 23 18:02:21 2020 +0530

    initial commit

diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
  

-- <absolute/relative path of file>

When you want to see the changes of specific file then you can write git log -- file name. Make sure that there is space between the -- and file name.

   $ git log -- gradle.properties

The -- filename causes git log to display only specific commit happened to this file only

  • Secure Hash Algorithm
  • author
  • date
  • commit message

This will display recent commit first or can say in descending order of timestamp.

--oneline <absolute/relative path of file>

   $ git log --oneline gradle.properties

The --oneline filename causes git log to display only specific commit happened to this file only

  • The first seven characters of SHA
  • The commit message

Commit made by particular author

You can see the commit made by specific user using the below command.

   $ git log --author"author-name"

Start at specific commit

You can display display the commit with specific SHA and all of the commits made before that commit.

   $ git log SHA

You can combine with other available options.

Search commit message

You can search commit message using the --grep.

   $ git log --grep="first commit"

--graph

   $ git log --graph

The --graph options enables you to view your git log as a graph. You can combine this with --oneline option you have learned from above.

   $ git log --graph --online

The --graph option is very useful in git log when you are working on feature on which multiple developers are working.

You can combine with --decorate option.

2 comments :