Bird
Raised Fist0
Gitdevops~10 mins

Viewing commit history with git log - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Viewing commit history with git log
Start in Git repo
Run 'git log'
Git reads commit history
Display commits one by one
User scrolls or exits
End
The flow shows how running 'git log' reads and displays commit history step-by-step until the user exits.
Execution Sample
Git
git log

# Shows commit history with commit ID, author, date, and message
This command lists commits in reverse chronological order with details.
Process Table
StepActionEvaluationResult
1Run 'git log'Git reads commit history from HEAD backwardsStarts displaying latest commit details
2Display commit #1Show commit hash, author, date, messageCommit #1 info shown on screen
3Display commit #2Show commit hash, author, date, messageCommit #2 info shown below #1
4Display commit #3Show commit hash, author, date, messageCommit #3 info shown below #2
5User scrolls or presses qIf user presses q, exit log viewExit git log display
6EndNo more commits or user exitedReturn to command prompt
💡 User exits by pressing 'q' or all commits displayed
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Displayed Commits Count01233
Current Commit ShownNoneCommit #1Commit #2Commit #3None (after exit)
Key Moments - 3 Insights
Why does git log show commits starting from the newest?
Git log reads commits from HEAD backwards, so the newest commit is shown first as seen in steps 1 and 2 of the execution_table.
How do I exit the git log view?
You press 'q' to quit, which is shown in step 5 of the execution_table where the user exits the log display.
What information does each commit entry show?
Each commit shows the commit hash, author, date, and message as detailed in steps 2-4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is displayed at Step 3?
ACommit #1 details
BCommit #2 details
CExit message
DNo output
💡 Hint
Check the 'Result' column for Step 3 in the execution_table
At which step does the user exit the git log view?
AStep 2
BStep 4
CStep 5
DStep 6
💡 Hint
Look for the step mentioning user pressing 'q' in the execution_table
If there were only two commits, how would the 'Displayed Commits Count' change after Step 4?
AIt would be 2
BIt would be 1
CIt would be 3
DIt would be 0
💡 Hint
Refer to variable_tracker for how commit count increments per step
Concept Snapshot
git log
- Shows commit history starting from newest
- Displays commit ID, author, date, message
- Scroll to see older commits
- Press 'q' to exit log view
- Useful to track changes over time
Full Transcript
When you run 'git log' in a Git repository, Git reads the commit history starting from the newest commit (HEAD) backwards. It displays each commit's details including the commit ID, author, date, and message. You can scroll through the commits to see older ones. When you want to stop viewing, press 'q' to exit and return to the command prompt. This command helps you see the history of changes made to the project.

Practice

(1/5)
1. What does the git log command do in a Git repository?
easy
A. Deletes the last commit from the repository
B. Shows the history of commits made in the repository
C. Creates a new branch in the repository
D. Displays the current status of files in the repository

Solution

  1. Step 1: Understand the purpose of git log

    The git log command is used to view the commit history in a Git repository.
  2. Step 2: Compare with other Git commands

    Other commands like git status show file status, and git branch manages branches, but git log specifically shows commits.
  3. Final Answer:

    Shows the history of commits made in the repository -> Option B
  4. Quick Check:

    git log = commit history [OK]
Hint: Remember: log means history or record [OK]
Common Mistakes:
  • Confusing git log with git status
  • Thinking git log deletes commits
  • Mixing git log with branch creation
2. Which of the following is the correct command to show a simplified one-line summary of each commit in Git?
easy
A. git log --oneline
B. git log --summary
C. git log --details
D. git log --short

Solution

  1. Step 1: Identify the option for one-line commit summary

    The --oneline option condenses each commit to a single line showing the commit hash and message.
  2. Step 2: Verify other options

    Options like --summary, --details, and --short are not valid git log options for this purpose.
  3. Final Answer:

    git log --oneline -> Option A
  4. Quick Check:

    --oneline = short commit list [OK]
Hint: Use --oneline for brief commit history [OK]
Common Mistakes:
  • Using non-existent options like --summary
  • Confusing --oneline with --short
  • Forgetting the double dash before options
3. Given the command git log -2 --oneline, what will be the output?
medium
A. Shows the last two commits in a detailed multi-line format
B. Shows all commits except the last two
C. Shows the last two commits each summarized in one line
D. Shows the first two commits in the repository

Solution

  1. Step 1: Understand the -2 option

    The -2 option limits the output to the last two commits only.
  2. Step 2: Understand the --oneline option

    The --oneline option shows each commit in a single line summary.
  3. Final Answer:

    Shows the last two commits each summarized in one line -> Option C
  4. Quick Check:

    -2 + --oneline = last two commits short [OK]
Hint: Combine -n with --oneline for short recent commits [OK]
Common Mistakes:
  • Thinking -2 shows first two commits
  • Expecting detailed multi-line output with --oneline
  • Confusing exclusion of commits with limiting output
4. You ran git log --oneline -p but got an error. What is the likely cause?
medium
A. The options --oneline and -p cannot be used together
B. You need to specify a branch name with the command
C. You must run git fetch before using git log
D. The repository has no commits yet

Solution

  1. Step 1: Understand the options --oneline and -p

    --oneline shows a brief summary, while -p shows patch (diff) details.
  2. Step 2: Check compatibility of options

    These two options conflict because one shows a short summary and the other shows detailed changes, so Git throws an error.
  3. Final Answer:

    The options --oneline and -p cannot be used together -> Option A
  4. Quick Check:

    --oneline + -p conflict = error [OK]
Hint: Avoid combining --oneline with -p; they conflict [OK]
Common Mistakes:
  • Assuming branch name is required for git log
  • Thinking git fetch fixes git log errors
  • Ignoring that empty repo causes no output, not error
5. You want to see the commit history with each commit showing the author, date, and a one-line message, all in a compact format. Which command should you use?
hard
A. git log --graph --decorate
B. git log --oneline --author-date-order
C. git log -p --stat
D. git log --pretty=format:"%h - %an, %ar : %s"

Solution

  1. Step 1: Understand the requirement for custom format

    You want author, date, and message in one line, so a custom format with --pretty=format: is needed.
  2. Step 2: Analyze the format string

    %h is short commit hash, %an is author name, %ar is relative date, and %s is commit message. This matches the requirement.
  3. Step 3: Check other options

    --oneline --author-date-order does not show author or date explicitly. -p --stat shows diffs and stats, not compact. --graph --decorate shows branch graph and refs, not author/date/message in one line.
  4. Final Answer:

    git log --pretty=format:"%h - %an, %ar : %s" -> Option D
  5. Quick Check:

    Custom format = author, date, message [OK]
Hint: Use --pretty=format for custom commit info display [OK]
Common Mistakes:
  • Using --oneline without author or date info
  • Expecting -p to show summary info
  • Confusing --graph with formatting output