![]() |
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) 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:
git log feature..main
This command shows commits that are in main but not in feature.
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) 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:
git log main...feature
This shows commits that are unique to both main and feature since they branched off.
git diff main...feature
This shows the differences between the two branches from the point they diverged. Difference Between Double Dot.. and Triple Dot…
|
Reffered: https://www.geeksforgeeks.org
Git |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |