Git commands

git log

git log: display the commit log (history).

The git log command is used to display the commit history of a Git repository. It shows a list of all the commits made to the repository, along with information about each commit, such as the commit hash, author, date, and commit message. This command is extremely useful for understanding the history of a project, tracking changes over time, and identifying specific commits that introduced bugs or added features.

By default, git log displays the commits in reverse chronological order, with the most recent commit appearing first. Each commit is identified by its unique hash, which is a 40-character string that uniquely identifies the commit. The commit message is a brief description of the changes made in that commit, which can help you understand the purpose of each commit.

There are many options you can use with git log to customize the output, such as filtering by author or date range, showing only certain branches, or displaying the changes introduced in each commit. Learning to use git log effectively can greatly enhance your ability to navigate and understand the history of a Git repository.

Some Git commands, such as git log, may put your terminal into pager mode, which is designed for browsing long lists. In this mode, you can scroll through the output using the and arrow keys on your keyboard (or PageUp and PageDown to scroll faster). To exit pager mode, press q.

Examples

Display the commit history using a standard view:

git log
Result:
commit c9dfc6eeeeb49a9661f39f80c587e9cc10a12c70 (HEAD -> main)
Merge: c369baa 2a0c1b5
Author: Elon Tusk <elon@dix.com>
Date:   2025-11-12
 
    Merge branch 'feature/cart' into main
 
commit c369baab2bd17ec1023a7af5f967b0fac8372d17
Author: Elon Tusk <elon@dix.com>
Date:   2025-11-12
 
    Update main branch
 
commit 2a0c1b53f2ce8176a93000e33226bb637f31d864 (feature/cart)
Author: Elon Tusk <elon@dix.com>
Date:   2025-11-12
 
    Add cart total calculation
 
commit 39c461a87ac0d283dd892b7abe74fa61175f71a8
Author: Elon Tusk <elon@dix.com>
Date:   2025-11-12
 
    Add cart model
 
commit 8ca0133bc67908e5ac49d452aaa8e00a52d18590
Author: Elon Tusk <elon@dix.com>
Date:   2025-11-12
 
    Initial commit

Display the commit history with abbreviated commit hashes and a simplified format:

git log --oneline
Result:
c9dfc6e (HEAD -> main) Merge branch 'feature/cart' into main
c369baa Update main branch
2a0c1b5 (feature/cart) Add cart total calculation
39c461a Add cart model
8ca0133 Initial commit

Display the history with graphical representation of the branch structure:

git log --oneline --graph
Result:
*   c9dfc6e (HEAD -> main) Merge branch 'feature/cart' into main
|\
* | c369baa Update main branch
| * 2a0c1b5 (feature/cart) Add cart total calculation
| * 39c461a Add cart model
|/
* 8ca0133 Initial commit

Display the commit history with a custom format, showing the abbreviated commit hash, author date, subject, and branch information. There's a whole bunch of placeholders you can use to customize the output, you can find the full list in the Git documentation if you ever need to.

git log --pretty=format:"%h %ad | %s%d [%an]"

Same with modern shorter syntax:

git log --format="%h %ad | %s%d [%an]"
Result:
c9dfc6e 2025-11-12 | Merge branch 'feature/cart' into main (HEAD -> main) [Elon Tusk]
c369baa 2025-11-12 | Update main branch [Elon Tusk]
2a0c1b5 2025-11-12 | Add cart total calculation (feature/cart) [Elon Tusk]
39c461a 2025-11-12 | Add cart model [Elon Tusk]
8ca0133 2025-11-12 | Initial commit [Elon Tusk]

Display the commit history for a specific file:

Note that the special -- option is used to tell Git that all the following arguments are file paths. This is necessary to avoid ambiguity when a file path may be mistaken for a branch or commit.

git log -- path/to/file.txt

Display commits within a specific date range:

git log --since="2023-01-01" --until="2023-01-31"

Display the commit history for a specific branch:

git log new-blog-design-branch

Display the commit history between two commits:

git log 9ds73k2..5ka4j3d
© 2024-2025 GitByBit.All rights reserved.