Skip to main content

How do you view the commit history in a repository?

You can view the commit history in Git in different ways, but the main and most important one is the git log command.

Let's go from the simplest to the more practical.


1. Basic way - git log

bash
git log

This command shows:

  • the list of commits from the newest to the oldest
  • the commit hash
  • the author
  • the date
  • the commit message

This is the classic interview answer.


2. A short and convenient history

In real work, a shortened form is often used:

bash
git log --oneline

It shows:

  • the short hash
  • the commit message one commit per line

Convenient when the history is large.


3. History with branches and merges

To see where branches and merges happened, use:

bash
git log --graph --oneline --all

Here:

  • --graph draws the branching diagram
  • --all shows all branches, not only the current one

It is a plus at an interview if you say that Git history is a graph, and it can be visualized.


4. History for a specific file

You can see how a single file changed:

bash
git log file.txt

This is useful if you need to understand:

  • who changed the file
  • when the change appeared
  • in which commit

5. Viewing the changes themselves

If you need to see what exactly changed, add:

bash
git log -p

Git will show the diff for each commit.


6. Limiting the history

Examples that interviewers like:

bash
git log -5 # last 5 commits git log --author=Ivan git log --since="2024-01-01"

Short answer for an interview

The commit history in Git is viewed with the git log command. It shows all commits of the current branch with the author, date, and message. For convenience, git log --oneline and git log --graph are often used.


A common mistake candidates make

"History can only be viewed in an IDE or on GitHub" Git stores history locally, and git log works without an internet connection.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.