git log

Commit ranges, left-right symmetric difference, and the -- path separator, checked on Git 2.39.5.

コマンドページの本文は現在英語です。

git log lists commits reachable from a revision, optionally limited to a range or to a path. This page focuses on ranges and the -- separator. It does not repeat the tutorial history chapter, and it avoids relative dates such as "1 week ago", which depend on the current clock.

Examples were checked on Git 2.39.5 in an isolated repository with a fixed author, committer, and UTC timestamps, so the abbreviated commit names in the output are stable for this history.

Examples were checked against Git 2.39.5. See the official documentation for the complete command.

Git command catalog → · Git tutorial overview →

Revision ranges

A..B lists commits reachable from B but not from A. After main and topic diverge, main..topic is the work only on topic, and topic..main is the work only on main.

A...B is the symmetric difference: commits reachable from either tip but not from the merge base. --left-right marks commits from the left name with < and commits from the right name with >. --graph draws the same split in the full history.

git log, git log A..B, git log A...B, --left-right, --graph

git log [<options>] [<revision-range>] [[--] <path>...]
git log --oneline --decorate --all --graph
git log --oneline A..B
git log --oneline --left-right A...B

List commits in a range, including the symmetric difference of two diverged branches.

ParameterDescription
A..BCommits reachable from B but not from A.
A...BCommits reachable from A or B, excluding the merge base. Use --left-right to see which side each commit came from.

Returns: One line per commit in the selected range, plus graph decorations when requested.

  • The abbreviated hashes below were measured on this exact history with the fixed dates in the script. They are not a general property of those commit messages.
bash
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'readme-a\n' > README.md
git add README.md
GIT_AUTHOR_DATE='2024-01-15T12:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T12:00:00+0000' git commit -m "Add README" >/dev/null
printf 'code-a\n' > app.txt
git add app.txt
GIT_AUTHOR_DATE='2024-01-15T13:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T13:00:00+0000' git commit -m "Add app" >/dev/null
git switch -c topic >/dev/null 2>&1
printf 'code-b\n' > app.txt
git add app.txt
GIT_AUTHOR_DATE='2024-01-15T15:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T15:00:00+0000' git commit -m "Edit app on topic" >/dev/null
git switch main >/dev/null 2>&1
printf 'readme-b\n' > README.md
git add README.md
GIT_AUTHOR_DATE='2024-01-15T14:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T14:00:00+0000' git commit -m "Edit README on main" >/dev/null
printf 'file-main\n' > main
git add main
GIT_AUTHOR_DATE='2024-01-15T16:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T16:00:00+0000' git commit -m "Add file named main" >/dev/null
git log --oneline --decorate --all --graph
echo "main..topic"
git log --oneline main..topic
echo "topic..main"
git log --oneline topic..main
echo "main...topic"
git log --oneline --left-right main...topic

Expected output

* 7a2e197 (HEAD -> main) Add file named main
* a8b47ed Edit README on main
| * f53cc96 (topic) Edit app on topic
|/  
* f03e59e Add app
* 884b62e Add README
main..topic
f53cc96 Edit app on topic
topic..main
7a2e197 Add file named main
a8b47ed Edit README on main
main...topic
< 7a2e197 Add file named main
> f53cc96 Edit app on topic
< a8b47ed Edit README on main

Related: git diff, Git tutorial: Inspect changes and history

Official documentation →

Path limiting and the -- separator

Arguments after -- are paths, never revisions. git log topic -- app.txt lists commits on topic that touched app.txt.

When a name is both a revision and a file, git log main is ambiguous and exits with a usage error. git log -- main limits the history to the file named main. Use -- whenever a path could be read as a revision or an option.

git log -- <path>

git log [<options>] [<revision-range>] -- [<path>...]

Limit the log to paths, and disambiguate a name that is both a branch and a file.

ParameterDescription
--Everything after this point is a pathspec, not a revision or option.
<path>A file or directory. Only commits that change that path are listed, still subject to the revision range.

Returns: The matching commits, or a fatal usage message when a name is ambiguous and -- is omitted.

Exit status

  • 128 — git log main exits 128 when main is both a branch and a file. Measured on Git 2.39.5.
bash
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'readme-a\n' > README.md
git add README.md
GIT_AUTHOR_DATE='2024-01-15T12:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T12:00:00+0000' git commit -m "Add README" >/dev/null
printf 'code-a\n' > app.txt
git add app.txt
GIT_AUTHOR_DATE='2024-01-15T13:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T13:00:00+0000' git commit -m "Add app" >/dev/null
git switch -c topic >/dev/null 2>&1
printf 'code-b\n' > app.txt
git add app.txt
GIT_AUTHOR_DATE='2024-01-15T15:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T15:00:00+0000' git commit -m "Edit app on topic" >/dev/null
git switch main >/dev/null 2>&1
printf 'readme-b\n' > README.md
git add README.md
GIT_AUTHOR_DATE='2024-01-15T14:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T14:00:00+0000' git commit -m "Edit README on main" >/dev/null
printf 'file-main\n' > main
git add main
GIT_AUTHOR_DATE='2024-01-15T16:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T16:00:00+0000' git commit -m "Add file named main" >/dev/null
git log --oneline main 2>&1
echo "exit-ambiguous=$?"
echo "path-main"
git log --oneline -- main
echo "topic-app"
git log --oneline topic -- app.txt

Expected output

fatal: ambiguous argument 'main': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
exit-ambiguous=128
path-main
7a2e197 Add file named main
topic-app
f53cc96 Edit app on topic
f03e59e Add app

Official documentation →