Git Log
-
To see the list of recent commits to the branch you are in, type in git log to see the last 5 commits. If you want to see a select number of the last commits, use git log -n [# number]
git log -n 3
-
Git log does have many built-in formatters for the commit history. If you want to see just oneline per commit in the git log, use git log --pretty=oneline. This will show the commit hash and the commit title in one line per commit.
git log --pretty=oneline
-
There is a short pretty formatter, use --pretty=short. This is same as the default git log output, but without the date.
git log --pretty=short
-
There is a medium pretty formatter, use --pretty=medium. This exactly the same as the default git log output.
git log --pretty=medium
-
The full pretty formatter (use --pretty=full) will just display the same detail as medium, but instead of date, it will show committer.
git log --pretty=full
-
The fuller pretty formatter (use --pretty=fuller) will display the same information as the full and also includes the author date and committer date.
git log --pretty=fuller
Filtering the git log
-
We can filter the git logs by date, author, and committer.
To see all the commits before a certain date, use git log --before=[date]
git log --before=2020-12-09
-
To see all the commits after a certain date, use git log --after=[date]
git log --after=2020-12-09
Customizing the git log output
-
We can customze the output of the git log
For example, if you want to see just the abbreviated commit hash, author name, date, and the commit title in oneline:
git log --pretty=format:"%h %an (%ar) %s"
Published on Last updated on