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
- git log
- git shortlog
- git show
- git rev-list
git log
- A shorter version of git log where it outputs the commit logs in just one line.
- Shows only the commit hash and message.
- Shows an overview on what files were added, modified and deleted for each commit.
- Shows an additional diff stat of what were added, modified and deleted for each commit.
- Shows the actual line/file modifications for each commit.
git log --author=<author>
- Limits the commits to the specified author.
- Limits the commits to ones with messages that matches the specified pattern.
- 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.
- Shows only the commit count per author.
- You can also add -n to sort by commit count per author.
git show
- Shows the actual line/file modifications for the latest 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.
- 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