December 30, 2016

698 words 4 mins read

Git Log Commands

Git Log Commands

This article shows some useful git log commands which include not only modifying the appearance of the commit log but also searching the content of the commit history.

Display commits on one line

$ git log --oneline
e9aeae9 Merge changes
5adc1e3 Changes to yaml dump and load
6273cd5 Reinstated json changes in case they are needed
3ba5e28 Further changes following testing (BG-55, BG-56)
72925a9 Change deprecated warn method to warning

To display a tree view of your commit history

$ git log --graph --oneline --all
*   5f62b09 Merge branch 'edit-term'
|\
| * ba862ae Changes for term edit functionality
| * 969ab08 Commit merge conflict changes
| * 527a0b5 Initial edit term code
* |   e9aeae9 Merge changes
|\ \
| |/
| * 6273cd5 Reinstated json changes in case they are needed
| * 3ba5e28 Further changes following testing (BG-55, BG-56)
| * 72925a9 Change deprecated warn method to warning
| * 7b6b2d8 Change term.term to term.name and add short description (BG-55, BG-56)
| * 08b7ec8 Reformat code Replace tabs with spaces and rearrange some imports Change prints to functions
* | 5adc1e3 Changes to yaml dump and load
|/
| * 34ef6e0 Term changes
| * 44c3731 Refined pencil
| * 499a4cc Add test x-editable work
|/
* 6d07e4b Change dumper to use mutiline dumper (BG-48)
* 4c3074e Multiline representer
* af84707 Change tabs to spaces on indent
*   5105af9 Merge branch 'tmp' into backuprestore2
|\
| *   1812164 WIP on master: f499732 Tweak pre margin for markdown code
| |\
| | * c1d4056 index on master: f499732 Tweak pre margin for markdown code
| |/
* | e294d8b Insert spaces in menu item (BG-51)
* |   95cdea6 Merge branch 'master' into backuprestore2
|\ \
| * | 863227c Remove Processes route (move to md page)
| * | 1ce74c5 Handle multiple mdtable id elements (BG-53)
| * | 2ab4e29 Fix markdown table styling (BG-53)
| * | 67b9bff Remove admins email list (BG-52) Should be specified in BG_SETTINGS configurati on file.
| * | 21b81e2 Add email error handler (BG-52)
| * | 77ad94a Added column sort order for rules admin view (BG-50)
| * | c61b44b Tweak markdown styles
| |/
* | 9e1d92a Add backup interface (BG-51)
|/
* f499732 Tweak pre margin for markdown code

Specify your own log format

$ git log --pretty=format:"%h - %an, %ar : %s"
e9aeae9 - Alan Tindale, 3 hours ago : Merge changes
5adc1e3 - Alan Tindale, 3 hours ago : Changes to yaml dump and load
6273cd5 - Alan Tindale, 3 hours ago : Reinstated json changes in case they are needed
3ba5e28 - Alan Tindale, 2 days ago : Further changes following testing (BG-55, BG-56)
72925a9 - Alan Tindale, 2 days ago : Change deprecated warn method to warning
7b6b2d8 - Alan Tindale, 2 days ago : Change term.term to term.name (BG-55, BG-56)
08b7ec8 - Alan Tindale, 2 days ago : Reformat code and replace tabs with spaces
6d07e4b - Alan Tindale, 13 days ago : Change dumper to use mutiline dumper (BG-48)
4c3074e - Alan Tindale, 13 days ago : Multiline representer
af84707 - Alan Tindale, 2 weeks ago : Change tabs to spaces on indent

Filter commit by commit message

Git accepts a regex pattern to search log messages and display matching commits.

git log --grep="theme"

You can also do a case insensitive search by passing the -i parameter.

git log -i --grep="theme"

Filter commits by files

You can search for commits that made changes to a particular file.

git log config.toml

This will search for the file config.toml in the root of the repository. You can also specify the path that the file is in or as an alternative, if you don’t know the path to the file, you can search by using the various globbing constructs:

git log **/config.toml
git log */*/config.toml
git log */config.*

Specifying the --all options searches all branches. According to the documentation:

Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as <commit>

Filter commits by file content

You can search for a specific string in the source code in the commit.

git log -S"theme = "
comments powered by Disqus