M
M
mpvcluuuuub2022-03-29 11:33:31
git
mpvcluuuuub, 2022-03-29 11:33:31

Difference between @~ and @^?

What is the difference between @^ and @~ , how can I use it? For example, when reset or rebase

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Kuznetsov, 2022-03-29
@mpvcluuuuub

These symbols are absolutely identical. Used for relative links back in history from some point.
For example git reset HEAD^3 will switch the current branch three commits back from the current state.

L
Lynn "Coffee Man", 2022-03-29
@Lynn

The difference is described in the documentation .
In particular @^, and @~indeed quite randomly, they choose the same thing, but they have a different meaning.
@synonym in this context HEAD.
^(=== ^1) - select the first parent of the commit. Most commits don't have anything else, so numbers other than 1 only make sense for merge commits.
~(=== ~1) - select a parent (if there are several, then the first one is selected).
But, for example, @^3choose the third parent of a commit. In 99.99% of cases, this will be a mistake, because in wildlife there are practically no more than two parents.
But it @~3means to choose the "great-grandfather" of the commit and this is equivalent to writing @^1^1^1(or@^^^).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question