Open In App

Double-Dot “..” vs. Triple-Dot “…” in Git Commit Ranges

Last Updated : 05 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Git, the distributed version control system, is a powerful tool for tracking changes in source code during software development. Among its many features, the syntax for specifying commit ranges is important for managing and understanding changes in your repository. Two such syntaxes are the double-dot `..` and the triple-dot `....` While they might seem similar, they serve different purposes and are used in distinct scenarios. This article explores the differences between `..` and `...`, explaining their usage and practical applications.

Understanding Commit Ranges:

Before diving into the specifics of `..` and `...` it’s essential to understand what commit ranges are. A commit range in Git allows you to specify a set of commits for various operations such as git log, git diff, and git rev-list. These ranges help you focus on a particular segment of the commit history, which is particularly useful for code reviews, debugging, and generating reports.

The Double-Dot `..`:

The double-dot syntax is used to specify a range of commits that are reachable from one commit but not from another. It is often used to see what changes exist between two branches or commits.

Syntax:

<commit1>..<commit2>

Usage:

When you use `A..B`, it means "all commits reachable from `B` that are not reachable from `A`.

Example: Suppose you have the following commit history.

* C (HEAD -> main)
* B
* A

To see the changes from commit A to commit C, you would use:

git log A..C

This command shows all commits that are reachable from C but not from A, effectively showing you the commits B and C.

Practical Applications:

  • Comparing Branches: When you want to see what commits are on one branch that are not on another.
git log feature..main

This command shows commits that are in main but not in feature.

  • Code Review: When reviewing changes, you can use the double-dot to focus on specific sets of commits.
git diff HEAD~2..HEAD

This shows the differences between the current commit and the one two commits back.

The Triple-Dot `...`:

The triple-dot syntax is used to find the common ancestor of two commits and then compare the two commits starting from that common ancestor. It is particularly useful for identifying differences and commonalities between two branches.

Syntax:

<commit1>...<commit2>

Usage:

When you use `A...B` it means all commits that are reachable from either `A` or `B` but not from their common ancestor.

Example: Suppose you have the following branches.

* C (feature)
| * B (main)
|/
* A

To see the commits that are different between the main and feature branches starting from their common ancestor, you would use:

git log main...feature

This command shows commits B and C.

Practical Applications:

  • Finding Divergent Commits: To see what commits are unique to each branch starting from their common ancestor.
git log main...feature

This shows commits that are unique to both main and feature since they branched off.

  • Merging and Rebasing: When preparing for a merge or rebase, understanding the differences between two branches can be critical.
git diff main...feature

This shows the differences between the two branches from the point they diverged.

Difference Between Double Dot.. and Triple Dot...

FeaturesDouble-Dot..

Triple-Dot ...

DefinitionSpecifies the range of commits between two commits.

Compares the commits reachable from either one of two commits but not both.

Syntaxcommit1..commit2

commit1...commit2

Usage in CommandsCommonly used with git log, git diff, etc., to list the commits that are reachable from commit2 but not from commit1.

Often used with git log to find commits that are in either commit1 or commit2, but not in both.

Commit InclusionExcludes commit1, includes all commits up to and including commit2.

Includes commits that are unique to commit1 and commit2, excluding their common ancestors.

Common ScenarioReviewing the commits in a branch since a specific commit: git log branchA..branchB.

Finding divergent commits between two branches: git log branchA...branchB.


Article Tags :

Explore