git relative commits - ghdrako/doc_snipets GitHub Wiki

  • HEAD: Indicates the current commit (most recent commit)
  • Parent commit: The following indicate the parent commit of the current commit —
  • HEAD ~1 or HEAD ~ or HEAD ^ : The parent to the current commit
  • HEAD^^ HEAD~2 : Grandparent commit — The following indicate the grandparent commit of the current commit
  • HEAD~3^2 : ^2 which indicates a second parent. So we take that out of the HEAD3^2 and what we have left is HEAD3 (i.e HEAD ~ 3 + ^2). What this means is that we are looking for the second parent of the great grandparent to the current commit HEAD.

The main difference between the caret^ and the tilde~ is when a commit is created from a merge.

A merge commit has two parents. With a merge commit, the ^ reference is used to indicate the first parent of the commit while ^2 indicates the second parent.

The first parent is the branch you were on when you ran git merge while the second parent is the branch that was merged in.

git rev-parse main #  

Określanie rodziców

Podobnie jak modyfikator ~, modyfikator ^ również przyjmuje po sobie opcjonalną liczbę.

Zamiast określać liczbę pokoleń do cofnięcia się (co robi ~), modyfikator ^ określa, do którego rodzica należy się odwołać po wykonaniu merge commita. Pamiętaj, że scalanie ma wielu rodziców, więc wybór ścieżki nie jest jednoznaczny.

Git zazwyczaj podąża za "pierwszym" rodzicem w górę od commitu scalającego, ale określenie liczby za pomocą ^ zmienia to domyślne zachowanie.

Jesli main wskazuje na merge commit i jeśli checkoutujemy main^ bez liczby na końcu, przejdziemy do pierwszego rodzica po merge commicie. Drugi rodzic:

git checkout main^2

Modyfikatory moga byc ze soba laczone

git checkout HEAD~^2~2

Stworzenie brancha na wybranym commicie - wskazjac go sciezka relatywna

git branch bugFix HEAD~^2~