Keywords: Git | tags | commit list
Abstract: This article provides a comprehensive exploration of how to retrieve commit lists between two tags in the Git version control system. By analyzing the syntactic differences in git log commands, particularly the distinction between two-dot (..) and three-dot (...) range operators, it explains how to precisely filter commit history. With code examples and practical application scenarios, the article offers a complete solution from basic to advanced levels, aiding developers in better managing release versions and code review processes.
Core Concepts of Git Range Operators
In the Git version control system, tags are commonly used to mark significant code milestones, such as software releases. When analyzing or reviewing code changes between two versions, retrieving the commit list between tags becomes a frequent requirement. Git provides the powerful git log command, which, combined with different range operators, allows flexible filtering of commit history.
Precise Filtering with the Two-Dot Operator (..)
The two-dot operator tagA..tagB is used to retrieve all commits reachable from tagB but not from tagA. This syntax is semantically equivalent to ^tagA tagB, where the ^ symbol denotes exclusion. For example, executing git log --pretty=oneline v1.0..v2.0 outputs all commits introduced in v2.0 but not present in v1.0. This format is particularly useful for inspecting new features or fixes in a specific release.
Symmetric Difference with the Three-Dot Operator (...)
The three-dot operator tagA...tagB computes the symmetric difference between two tags, i.e., it retrieves all commits reachable from either tagA or tagB, but not from both. This is equivalent to combining git log tagA..tagB tagB..tagA. For instance, git log --pretty=oneline v1.0...v2.0 displays all differing commits between v1.0 and v2.0, including changes in both directions. This format is valuable when comparing the complete differences between branches or tags.
Formatted Output and Advanced Applications
Using the --pretty option, the display format of the commit list can be customized. --pretty=oneline compresses each commit into a single line, showing the commit hash and message summary, ideal for quick overviews. Other formats like --pretty=format:"<custom string>" allow finer control, such as including author, date, and other details. In practice, combining with the --graph option visualizes the branch structure of commit history, enhancing readability.
Practical Scenario Analysis and Best Practices
In continuous integration and release management, accurately retrieving commit lists between tags is crucial. For example, when generating release notes, the two-dot operator can automatically extract all commit messages for a new version. In code reviews, the three-dot operator helps teams fully understand all changes between versions, preventing omissions. It is recommended to integrate these commands into scripts for automated workflows and always verify tag existence to avoid errors.