Git & GitHub - Viewing History
Commands to view the history of a repository
Viewing the history of a repository is crucial for tracking changes, understanding the evolution of a project, and collaborating with others. This guide explains the commands used to view the history of a Git repository.
Key Points:
- Git provides several commands to view the history of a repository.
- The
git log
command is the most commonly used for viewing commit history. - Additional options and commands can display history in different formats and levels of detail.
Using git log
The git log
command displays the commit history of the repository. By default, it shows commits in reverse chronological order.
# View the commit history
$ git log
This command outputs a list of commits with their hashes, authors, dates, and messages.
Formatting git log
Output
You can customize the output of git log
using various options:
# One-line summary for each commit
$ git log --oneline
# Detailed commit history with patches
$ git log -p
# Limit the number of commits displayed
$ git log -n 5
# Display commits for a specific file
$ git log -- filename.txt
Using git show
The git show
command displays detailed information about a specific commit, including the changes made in that commit.
# Show details of a specific commit
$ git show
Using git diff
The git diff
command shows the differences between commits, branches, or the working directory and the staging area.
# Show changes between working directory and staging area
$ git diff
# Show changes between staging area and last commit
$ git diff --cached
# Show changes between two commits
$ git diff
Using git blame
The git blame
command shows who made changes to each line of a file and when. This is useful for understanding the history of a file.
# Show blame information for a file
$ git blame filename.txt
Using git reflog
The git reflog
command shows a log of all the references (HEAD, branches, etc.) that have been updated in the repository, including commits that might not be visible in the normal commit history.
# Show reference log
$ git reflog
Summary
This guide covered various commands to view the history of a Git repository, including git log
, git show
, git diff
, git blame
, and git reflog
. Understanding these commands is essential for tracking changes, debugging issues, and collaborating effectively in Git.