git log --oneline
- Version
- 2.51
- Review
- Draft
Summary#
git log --oneline prints an abbreviated commit ID and the subject for each commit visited. Add a count to limit the output.
Syntax#
git log --oneline -5
git log --oneline main..topic
Example#
(
set -eu
scratch=$(mktemp -d "${TMPDIR:-/tmp}/devlookup-git.XXXXXX")
trap 'rm -rf -- "$scratch"' EXIT
unset GIT_CONFIG_GLOBAL $(git rev-parse --local-env-vars)
export GIT_CONFIG_NOSYSTEM=1 GIT_TEMPLATE_DIR= LC_ALL=C
export HOME="$scratch" XDG_CONFIG_HOME="$scratch" GIT_ATTR_NOSYSTEM=1
mkdir "$scratch/work"
cd "$scratch/work"
git init -q -b trunk
git -c user.name="Reference Example" -c user.email=example@example.invalid commit --allow-empty -qm "Create menu"
git -c user.name="Reference Example" -c user.email=example@example.invalid commit --allow-empty -qm "Add keyboard focus"
# Commit IDs and abbreviation lengths can vary.
git --no-pager log --oneline --no-decorate -2 |
sed 's/^[0-9a-f][0-9a-f]* /<short-id> /'
)
Expected output#
<short-id> Add keyboard focus
<short-id> Create menu
Common mistakes#
By default the history starts from HEAD. Use --all when you intend to include histories reachable from other refs. Use full commit IDs for durable references.
Version applicability#
Git 1.6.3 added --oneline. Git 1.7.2 documents the example's --no-decorate switch.
The complete example requires Git 2.28 or later for git init -b.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0