In this short article, we’ll be exploring some quick commands that can help us in digging through our repositories’ history of commits. We’ll look at git git log git shortlog git show git rev-list git log git log --oneline A shorter version of where it outputs the commit logs in just one line. git log Shows only the and . commit hash 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 of what were added, modified and deleted for each commit. diff stat 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. is case sensitive and means . A added You can replace with to limit the commits where the specified file was modified. A M Or replace with for when the file was deleted. D git log --diff-filter=a <file> Similar to the previous but with lowercase case letters. Lowercase means to . a exclude added Limits for commits where the file was added modified or deleted. not e.g Same logic for lowercase or . m d git shortlog or git shortlog git shortlog -n Summarizes the output for . git log Groups commits by author and title. The sorts the result by commit author in alphabetical order. -n git shorlog -s Shows only the commit count per author. You can also add to sort by commit count per author. -n 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 of what were added, modified and deleted for the specified commit. diff stat git rev-list git rev-list --count HEAD Shows the total commit count for the repository. You can also replace with a branch name or a HEAD 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
Share Your Thoughts