Show the commit history in one line per commit

Description: Show the history of a repository with one line per commit, and then show only the last 2 commits.

Hint:

  • Use --oneline and the option -n (or -2).

Solution

Terminal output

$ git log –oneline
a9b08d4 (HEAD -> main) Update file again
f95aab8 Update file
ad07eb3 Add file
$ git log –oneline -2
a9b08d4 (HEAD -> main) Update file again
f95aab8 Update file

How it works

  • --oneline shows the short hash and the title of each commit.
  • -2 limits the output to two commits.

Read Git Log.


Learn more about the similar topics:
Tutorials
Git Init
Git Status
Git Add
Git Commit
Git Log
Git Diff
Git Ignore (.gitignore)
Exercises & Assignments
Check the status of files in a Git repository
Stage only selected files and commit them separately
Show the commit history in one line per commit
See the changes of a file before staging and before commit
Ignore all .log files with .gitignore
Unstage a file
Delete a file with git rm
Interview Questions & Answers
How can you add files to Git?
How can you commit a file in Git?
What are the common files to ignore in Git?
How to remove untracked files in Git?
What is the staging area in Git?
What is the difference between git add and git commit?
What is HEAD in Git?