Plain git log gives each commit about six lines: the full 40-character hash, the author, the date, a blank line, the message, another blank line. A repository with a few hundred commits becomes a long scroll in which branches and merges are invisible. The same history fits on one screen with three flags, and with a format string it can be shaped into exactly the columns a person, or a script, needs. Everything below was run against a small test repository built for this post, with two authors, a feature branch, a merge and a tag, and the output shown is what Git printed.
One line per commit
The –oneline shortcut
The git log documentation describes --oneline as “a shorthand for --pretty=oneline --abbrev-commit used together.” On the test repository it printed:
4c19ed9 Merge branch 'feature'
5db7533 Fix typo in header
894cbd6 Raise timeout to 60
e006895 Set request timeout
60326e4 Add login form
7a69ff8 Initial commit
What gets dropped
The pretty formats page shows the oneline layout as a hash followed by the title line, “designed to be as compact as possible.” Author, date and the body of each message are gone. So is the shape of the history: the list above reads like a straight line, even though two of those commits were made on a separate branch.
Abbreviated, not shortened for good
The seven-character hashes are prefixes of the full 40-character ones. %H printed 4c19ed9ba3bda6b2417dd84b079b1f6a407642cd for the merge commit, and 4c19ed9 is simply its start. Git accepts the short form wherever it expects a commit, as long as the prefix is unique in the repository.

Drawing the branches
–graph, –decorate and –all
Three more flags restore what --oneline hid. --graph will “Draw a text-based graphical representation of the commit history on the left hand side of the output.” --decorate will “Print out the ref names of any commits that are shown.” And --all acts as if every ref in refs/, along with HEAD, had been listed on the command line, so commits on branches other than the current one appear too.
The result
git log --oneline --graph --decorate --all printed:
* 4c19ed9 (HEAD -> main, tag: v1.0) Merge branch 'feature'
|\
| * 894cbd6 (feature) Raise timeout to 60
| * e006895 Set request timeout
* | 5db7533 Fix typo in header
|/
* 60326e4 Add login form
* 7a69ff8 Initial commit
Reading it
Each asterisk is a commit; the lines show parentage. The history split after “Add login form,” the right-hand column carried the feature branch’s two commits, and the left-hand column carried a fix on main. The merge commit at the top has two parents, which is why the graph opens into two lines below it. The decorations in parentheses show where HEAD, the branches and the tag point.
Making it permanent
Nobody types that every time. Running git config alias.lg "log --oneline --graph --decorate --all" made git lg print the same graph. Set that way, the alias lives in the repository’s own configuration.
Custom formats with placeholders
Choosing the columns
--pretty=format: takes a template. The pretty formats page lists the placeholders, including %h for “abbreviated commit hash,” %an for “author name,” %ad for “author date (format respects –date= option)” and %s for “subject.” Running git log --pretty=format:'%h %an %ad %s' --date=short printed:
4c19ed9 Ada 2025-12-06 Merge branch 'feature'
5db7533 Ada 2025-12-05 Fix typo in header
894cbd6 Bob 2025-12-04 Raise timeout to 60
e006895 Ada 2025-12-03 Set request timeout
60326e4 Ada 2025-12-02 Add login form
7a69ff8 Ada 2025-12-01 Initial commit
More placeholders worth knowing
%H is the full commit hash, %P the “parent hashes,” %ae the author email, %ar the author date expressed relative to now, %d the “ref names, like the –decorate option,” and %n a newline. A format of '%H%n%P' on the merge commit printed its own full hash on one line and two parent hashes on the next, the clearest proof that a merge commit is just a commit with two parents.
Adding color
Color codes go inside the template: %C(yellow)%h%Creset turns the hash yellow and %Creset puts the color back. A format with yellow hashes, blue dates, green author names and %C(auto)%d for decorations produced lines like 894cbd6 2025-12-04 Raise timeout to 60 (Bob) (feature).
Why the color vanished in a pipe
When that output was piped to another command, no color codes came through at all. That’s documented behavior. The pretty formats page says that “By default, colors are shown only when enabled for log output” through Git’s color settings or --color, “respecting the auto settings of the former if we are going to a terminal.” A terminal gets color; a file or a pipe gets plain text unless --color=always is added. That default is what keeps a colorful alias from polluting a script’s input.

Filtering what gets shown
By author
--author limits output to commits “with author/committer header lines that match the git log --author=Bob --oneline returned the one commit Bob made: 894cbd6 Raise timeout to 60.
By content, with the pickaxe
-S searches the changes themselves. The documentation says it looks “for differences that change the number of occurrences of the specified git log -S TIMEOUT=60 --oneline returned only 894cbd6, the commit that introduced that exact text. A message search would miss it if the commit message never mentioned the value. The pickaxe finds it anyway.
By date
--since shows “commits more recent than --until caps the other end. git log --since=2025-12-04 --until=2025-12-05 --oneline returned one commit, 5db7533. The commit from December 4 at noon fell outside. The test ran at about 8 p.m., and adding explicit times, --since="2025-12-04 00:00" --until="2025-12-05 23:59", brought it back: both December commits appeared. A bare date doesn’t reliably mean the whole calendar day, so spelling out the hour removes the guesswork.
By file
Adding -- config.txt limits the log to commits that “explain how the files that match the specified paths came to be.” In the test that meant the two commits on the feature branch, the only ones that touched config.txt. The -- separates paths from branch names, which matters when a file and a branch share a name.
The change itself
Adding -p shows the patch under each commit. git log -p -1 --format='%h %s' -- config.txt printed the latest commit to touch that file, 894cbd6 Raise timeout to 60, followed by its diff: a line removed reading -TIMEOUT=30 and a line added reading +TIMEOUT=60. Combined with the pickaxe or a path, it turns the log into a searchable record of exactly what changed, line by line, and who changed it.
Merges, ranges and summaries
Following only the main line
On a branch that takes in many merges, --first-parent cuts the noise. The documentation says it follows “only the first parent commit upon seeing a merge commit.” git log --first-parent --oneline printed four commits: the merge, the typo fix and the two original commits. The feature branch’s internal work collapsed into the single merge.
Merges only, or none
--merges prints “only merge commits” and --no-merges drops any commit “with more than one parent.” In the test, --merges returned just 4c19ed9, and --no-merges counted 5 commits, the other five.
What one branch has that another doesn’t
The double-dot range answers the everyday question before a merge or a push. The documentation explains that origin..HEAD means commits “reachable from the current commit (i.e. HEAD), but not from origin.” After the merge, git log --oneline main..feature printed nothing, because main already contained everything on feature. Reversed, feature..main listed the merge and the typo fix, the two commits main had that feature didn’t.
Which files changed
--stat will “Generate a diffstat.” For Bob’s commit it added a summary under the message: config.txt | 2 +- and “1 file changed, 1 insertion(+), 1 deletion(-).” A changed line in Git’s diff counts as one deletion and one insertion, which is why a single edited line shows up as both.

Formats for scripts
Stable fields over pretty output
For a script, the decorated graph is the wrong tool. A format string with fixed fields is easier to parse, and full hashes from %H avoid any chance of an abbreviation becoming ambiguous later. A template such as '%H|%an|%ad|%s' with --date=short produces one record per line with a predictable separator.
Why a separator is hard to choose
A commit subject can contain almost any character, including a pipe. The pretty formats page documents a way around that: “%x followed by two hexadecimal digits is replaced with a byte with the hexadecimal digits’ value.” Running --format='%h%x00%s' through od -c showed a real \0 byte between each hash and subject, a separator no one can type into a commit message. %x09 gives a tab, which is easier to read and still rare in subjects.
Pager behavior in scripts
In a terminal, Git sends long output through a pager so it can be scrolled. These tests set GIT_PAGER=cat so every result printed straight to standard output, which is also the simplest way to keep a script from stopping to wait on a pager.
Sources
- git-log Documentation, Git: https://git-scm.com/docs/git-log
- Pretty Formats, Git documentation: https://git-scm.com/docs/pretty-formats
