In projects using Git for version control, viewing commit history is a commonly used and important feature that helps developers track and understand the evolution of the project.
To view Git commit history, you typically use the git log command. This command displays all commit history, including the commit ID, author, date, and commit message. Here are some common ways to use the git log command:
-
Basic Usage:
shellgit logThis command lists all commits, showing detailed commit IDs, author information, dates, and commit messages.
-
Concise Display:
shellgit log --onelineThis command displays each commit in a concise manner, showing one line per commit, typically including the short commit ID and commit message.
-
Limit the Number of Commits:
shellgit log -n <limit>Here,
<limit>can be replaced with any number to limit the number of log entries displayed. For example,git log -n 3shows the most recent three commits. -
View History of a Specific File:
shellgit log -- <file>This command can be used to view all commits related to a specified file. For example,
git log -- README.mddisplays all commits involving theREADME.mdfile. -
Graphical Display:
shellgit log --graphThis option displays the branch merge history in a graphical format.
-
Time Range:
shellgit log --since="2020-01-01" --until="2020-12-31"This command displays commit history within the specified time range.
For example, suppose you need to quickly view the most recent five commits in a project and see the graphical branch flow. You can use the following command:
shellgit log -n 5 --graph --oneline
This allows you to quickly get an overview of the latest five commits and understand the relationships between branches in a graphical manner. By doing this, you can effectively track and understand the project's development history and status.