Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between ~ and ^ in git

Tags:

git

I asked this question long ago but I still don't know what do ~ and ^ mean in this answer:

If you're talking about a remote branch, say, origin/master, you can use ~ and ^ to refer to ancestor commits relative to a branch the same way you can with local branches

What's the difference?

like image 427
OscarRyz Avatar asked Dec 11 '22 18:12

OscarRyz


1 Answers

^ means "(first) parent of". ~ is similar, but it takes a number as an argument and basically means "ancestor of". So, for example:

HEAD            = latest commit
HEAD^  = HEAD~1 = parent of latest commit
HEAD^^ = HEAD~2 = grandparent of latest commit
HEAD~100        = 100th ancestor of latest commit
like image 53
mipadi Avatar answered Jan 03 '23 14:01

mipadi