乐闻世界logo
搜索文章和话题

How to View Commit History with Git?

2024年7月4日 09:39

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:

  1. Basic Usage:

    shell
    git log

    This command lists all commits, showing detailed commit IDs, author information, dates, and commit messages.

  2. Concise Display:

    shell
    git log --oneline

    This command displays each commit in a concise manner, showing one line per commit, typically including the short commit ID and commit message.

  3. Limit the Number of Commits:

    shell
    git log -n <limit>

    Here, <limit> can be replaced with any number to limit the number of log entries displayed. For example, git log -n 3 shows the most recent three commits.

  4. View History of a Specific File:

    shell
    git log -- <file>

    This command can be used to view all commits related to a specified file. For example, git log -- README.md displays all commits involving the README.md file.

  5. Graphical Display:

    shell
    git log --graph

    This option displays the branch merge history in a graphical format.

  6. Time Range:

    shell
    git 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:

shell
git 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.

标签:Git