samshers
samshers

Reputation: 3660

git: what is difference between tilde (~) and caret (^)

Below is the git output for show-rev

$ git name-rev  --all

2651919f941c11581c794b40aadb2028c4f52ab4 joincolumn_issue
2617f2a1410ce0ec8ea268bbb073008b73490e78 master~2
292def505dd3cdbfd9ac974396775683b5f4c288 ls
0ec9116840a3f21c0b800617c29b7ddab5fda928 joincolumn_issue~2
ee9bb706c8fcc329fac4acf69ad6b684f1069170 master~1
d56a6751771b1f62d9ceb0bcce9a2391c004ee44 master^2
3d80a12ed375c6a9572cde39b5be0722c8cb6439 joincolumn_issue~1
df1834dbe560c2c95c8abaeec494eb1767b96a1e master

As you can see there are lines with master^2 and master~2 So, wondering what is the difference between these two and also the output is out of chronological order.

Further the git graph shows as below

$ git log --all --oneline --graph

* 2651919 (origin/joincolumn_issue, joincolumn_issue) changing to @JoinColumn(name="country_nm")
* 3d80a12 hibernate ignoring joinColumn value
* 0ec9116 changing name in joinColumn is breaking
| * 292def5 (origin/mappedBy, mappedBy, ls) OneToMany using mappedBy
|/
*   df1834d (HEAD -> master, origin/master) Merge branch 'master' of https://github.com/samshers/graphql-hibernate
|\
| * d56a675 fixed country null issue
* | ee9bb70 fixed country null issue
|/
* 2617f2a hibernate cascade error issue. country field in state table set to null

Upvotes: 2

Views: 1704

Answers (1)

bk2204
bk2204

Reputation: 76429

The syntax BRANCH^ means the first parent of BRANCH. The syntax BRANCH^n means the nth parent of branch. In other words, BRANCH^ is equivalent to BRANCH^1. It's only possible to have more than one parent when you have a merge, so BRANCH^2 (and, for octopus merges, BRANCH^3 and higher) are only used when you have a merge.

The syntax BRANCH~ is equivalent to BRANCH^1, and BRANCH~n is equivalent to adding n copies of ^1 to the end of BRANCH. In other words, the latter is the nth parent of BRANCH following only the first parent in each case.

Typically, the first parent is the main branch, and the second and subsequent parents are the side branches that are merged into it, so these syntaxes are optimized for this case.

There are also other syntaxes that use the caret, but they work differently and mean different things. You can see all about the syntax of Git revisions with man gitrevisions.

Upvotes: 10

Related Questions