What are the differences between double-dot .. and triple-dot ... in Git commit ranges?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Differences Between Double-Dot ".." and Triple-Dot "..." in Git Commit Ranges
When working with Git, especially for comparing branches or fetching a range of commits, understanding the nuances of the double-dot (..) and triple-dot (...) notations is vital. These symbols allow developers to specify commit ranges, which can be leveraged in commands such as git log, git diff, and others, to glean insights into the differences or changes between branches or commits.
Technical Explanation
Double-dot (..)
The double-dot (..) notation in Git is used to specify a range of commits. It requires two commits or branches as input and is inclusive of the first and exclusive of the second. Essentially, A..B translates to "commits that are reachable from B but not from A."
• Usage: git log A..B
• Interpretation: The range includes all commits that exist in B but not in A.
Triple-dot (...)
The triple-dot (...) notation is slightly more complex. It compares the differences between the tips of two branches and identifies commits that are unique to each branch starting from their common ancestor.
• Usage: git log A...B
• Interpretation: The result is a symmetric difference. It includes the commits that are unique to A and B from their common ancestor, excluding those present in both.
Examples
Let's assume we have a Git repository with branches main and feature, and the commit history looks like this:
• C4 - feature • C2 - common ancestor • C1
• Using Double-dot (e.g., main..feature):
• Command: git log main..feature
• Output: Displays commit C4 since it is present in feature and not in main.
• Using Triple-dot (e.g., main...feature):
• Command: git log main...feature
• Output: Displays commits C3 and C4. Commit C2 is the common ancestor, so it is not included.
• Common Use Cases:
• Double-dot (..): Primarily used when reviewing changes that are solely in one branch but not yet merged into another. Useful for code reviews.
• Triple-dot (...): Typically useful for getting a broader view of differences between branches from their common ancestor, often used for merging strategies and understanding branch divergences.
• Commands Beyond git log:
• git diff A..B: Compares changes in B relative to A.
• git diff A...B: Shows changes that happened on either side.
• Understanding Symmetric Difference:
• The triple-dot operator essentially highlights how two branches have diverged from their shared path, shedding light on new contributions that haven't been shared yet.
• Performance Considerations:
• Using these operators judiciously can lead to more efficient Git workflows, especially in larger projects with complex histories.
Related reading
- What are the differences between git branch, fork, fetch, merge, rebase and clone?
- What are the differences between git clone --shared and --reference?
- What are the differences between git commit and git push?
- What are the differences between git commit and git push?
- What are the differences between git remote prune, git prune, git fetch --prune, etc
- What are the differences between .gitignore and .gitkeep?
- What do "branch", "tag" and "trunk" mean in Subversion repositories?
- What do I need to read to understand how git works?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.