Hackernoon logoGit Commands You Can Use To Dig Through Your Git History by@micogongob

Git Commands You Can Use To Dig Through Your Git History

Mico Gongob Hacker Noon profile picture

@micogongobMico Gongob

PH Software Engineer

In this short article, we’ll be exploring some quick git commands that can help us in digging through our repositories’ history of commits. We’ll look at

  1. git log
  2. git shortlog
  3. git show
  4. git rev-list

git log

git log --oneline
  • A shorter version of git log where it outputs the commit logs in just one line.
  • Shows only the commit hash and message.
git log --name-status
  • Shows an overview on what files were added, modified and deleted for each commit.
git log --stat
  • Shows an additional diff stat of what were added, modified and deleted for each commit.
git log -p
  • Shows the actual line/file modifications for each commit.
git log --author=<author>
  • Limits the commits to the specified author.
git log --grep=<pattern>
  • Limits the commits to ones with messages that matches the specified pattern.
git log -S<string>
  • Limits the commits where the first version of the specified string was introduced.
git log --diff-filter=A <file>
  • Limits the commits where the specified file was added.
  • A is case sensitive and means added.
  • You can replace A with M to limit the commits where the specified file was modified.
  • Or replace with D for when the file was deleted.
git log --diff-filter=a <file>
  • Similar to the previous but with lowercase case letters.
  • Lowercase a means to exclude added.
  • Limits for commits where the file was not added e.g modified or deleted.
  • Same logic for lowercase m or d.

git shortlog

git shortlog
 or 
git shortlog -n

  • Summarizes the output for git log.
  • Groups commits by author and title.
  • The -n sorts the result by commit author in alphabetical order.
git shorlog -s
  • Shows only the commit count per author.
  • You can also add -n to sort by commit count per author.

git show

git show
  • Shows the actual line/file modifications for the latest commit.
git show <commit>
  • Shows the actual line/file modifications for the specified commit.
git show <commit> --name-status
  • Shows an overview on what files were added, modified and deleted for the specified commit.
git show <commit> --stat
  • Shows an additional diff stat of what were added, modified and deleted for the specified commit.

git rev-list

git rev-list --count HEAD
  • Shows the total commit count for the repository.
  • You can also replace HEAD with a branch name or a commit hash

Conclusion

We’ve looked at the four different git commands and their respective arguments to help us dig different insights about our git history. You can try these with your own repositories and also explore different combination of arguments, eg:

git log -Sspring-boot-starter-actuator -p

or

git log --name-status --diff-filter=a .gitignore

Hopefully some of these examples can help you in your day to day coding.

Originally published at https://micogongob.com/git-commands-you-can-use-to-dig-through-your-git-history

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.