0
0
Gitdevops~10 mins

git log formatting options - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - git log formatting options
Run git log command
Parse commits in repo
Apply formatting options
Display formatted commit logs
User reads output or pipes it
The git log command reads commits, applies formatting options, and shows the formatted commit history.
Execution Sample
Git
git log --pretty=format:"%h - %an, %ar : %s" -3
Shows last 3 commits with short hash, author name, relative date, and commit message.
Process Table
StepActionInput/OptionResult/Output
1Run commandgit log --pretty=format:"%h - %an, %ar : %s" -3Starts reading last 3 commits
2Read commit 1Commit dataCommit hash: abc123, Author: Alice, Date: 2 days ago, Message: Fix bug
3Format commit 1%h - %an, %ar : %sabc123 - Alice, 2 days ago : Fix bug
4Read commit 2Commit dataCommit hash: def456, Author: Bob, Date: 5 days ago, Message: Add feature
5Format commit 2%h - %an, %ar : %sdef456 - Bob, 5 days ago : Add feature
6Read commit 3Commit dataCommit hash: 789abc, Author: Carol, Date: 1 week ago, Message: Update docs
7Format commit 3%h - %an, %ar : %s789abc - Carol, 1 week ago : Update docs
8Display outputAll formatted commitsShows 3 formatted commit lines
9EndNo more commits or limit reachedStops reading commits
💡 Limit of 3 commits reached, so git log stops reading more commits
Status Tracker
VariableStartAfter 1After 2After 3Final
commit_count01233
commit_hashabc123def456789abc789abc
formatted_lineabc123 - Alice, 2 days ago : Fix bugdef456 - Bob, 5 days ago : Add feature789abc - Carol, 1 week ago : Update docs789abc - Carol, 1 week ago : Update docs
Key Moments - 3 Insights
Why does git log stop after 3 commits even if the repo has more?
Because the -3 option limits output to 3 commits, as shown in execution_table row 9 where the limit is reached.
What does %h mean in the format string?
%h means the short commit hash, as seen in execution_table rows 3, 5, and 7 where hashes like abc123 appear.
How does git log know which commits to show first?
Git log shows commits starting from the newest going backward, shown in execution_table rows 2, 4, and 6 reading commits in order.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the formatted output at step 5?
Aabc123 - Alice, 2 days ago : Fix bug
Bdef456 - Bob, 5 days ago : Add feature
C789abc - Carol, 1 week ago : Update docs
DNo output yet
💡 Hint
Check the 'Format commit 2' action at step 5 in the execution_table
At which step does git log stop reading commits due to the limit?
AStep 7
BStep 8
CStep 9
DStep 3
💡 Hint
Look at the exit_note and step 9 in the execution_table
If we remove the -3 option, how would the commit_count variable change?
AIt would increase beyond 3
BIt would stay at 3
CIt would be 0
DIt would decrease
💡 Hint
Refer to variable_tracker row for commit_count and the effect of the -3 limit
Concept Snapshot
git log formatting options:
Use --pretty=format:"..." to customize commit output.
Common placeholders: %h (short hash), %an (author name), %ar (relative date), %s (subject).
Limit commits with -n (e.g., -3 for last 3 commits).
Output shows commits newest first.
Useful for concise, readable commit history.
Full Transcript
The git log command reads commits from the repository starting with the newest. When you add formatting options like --pretty=format, git log applies those to each commit's data. For example, %h shows the short commit hash, %an the author name, %ar the relative date, and %s the commit message. Using -3 limits output to the last three commits. The execution table shows each step: reading a commit, formatting it, and displaying it. Variables like commit_count track how many commits have been processed. Git stops reading commits once the limit is reached. This helps you see a clean, customized list of recent commits.