We can get the git commit logs with the git log
command.
git log
Get the latest n commits
We can get the latest n commits by running git log -n
. Let’s say that we want to get the latest 2 commits.
git log -2
Get all the commits since a date
We can filter the commits based on time. Let’s say that we want all the commits since 2022-01-17.
git log --since 2022-01-17
Get all the commits until a date
Similarly, we can get all the commits until a specific date as follows:
git log --until 2022-01-16
Get all the commits by an author
We can get all the commits done by a specific author. For example:
git log --author=pipinho13
Get all the commits between two SHAs
We can get the logs between two SHAs as follows:
git log <XXX>...<YYY>
where XXX and YYY are the corresponding SHAs. Note that we can replace the <YYY> with the HEAD, if we want to get all the commits from the <XXX> up to now. I.e.
git log <XXX>...HEAD
Get all the commits that are related to a file
We can filter the logs of the commits by a file. Let’s say that we want to get the logs of the README.txt
git log README.md
Get all the commits using an expression
We can use the powerful “grep” command to filter the commits. Usually, we search for an expression in the commit message. For example let’s get all the commits that include the word “wrong” in the commit message:
git log --grep="wrong"