Git Relative Positioning

Symbols such as ^ and ~ could be used for relative positioning for #202204261252. It could be applied to HEAD itself, branch name or tag, but not to individual commit.

^ means moving up to one commit or its nearest parent from the current commit. If followed by number, let’s say \(x\), it will point to the \(x\)th parent of the commit in the Git DAG. You can visualise it in git log --graph. This could be useful when dealing with repository that use #202204261123 often.

~{#} means moving up along the commit in a linear sense. This means that it will always prioritise the nearest parent of the commit. If number is not specified, it behaves the same with ^. Otherwise, it will move up \(x\)-th times linearly along the commit history.

Links to this page
  • Git Revert Commits

    We can reverse changes in a Git repository using two commands: reset and revert. These commands could be used alongside with symbols# like ^ and ~.

  • Git Push

    One can pass in refspecs in the format of {local_branch}:{remote_branch} into the command push {remote} with 202205251604# in order to push the local branch# to a specific remote branch that is not referred by the local branch. If you do not name the local branch, the remote branch will be deleted instead. You could do this with 202205251612 and 202204262031 too.

  • Git Pull

    Similar to 202205251600, you can use refspecs with the format of {remote_branch}:{local_branch} for the command pull {remote} with 202205251604#. If the remote branch# is not named, it will create a local branch that #202205251612 all commits on the remote repository instead, and then merge it to the checkout branch.

  • Git Merge

    Note: When using ^ symbol with commits, be aware whether the commit has multiple parents. See 202205251604#.

  • Git HEAD

    Git HEAD is pointing to the current working commit. One could move the HEAD along the commit history in the repository without restrictions. We could move the HEAD to specific position by using checkout {commit} either by specifying the branch name, tag, individual commit or by using 202205251604#.

  • Git Branch Creation

    If you want to immediately check out to the branch upon creation, run checkout -b {branch-name} {commit} where the commit is an optional argument that specifies where the starting point the branch should be at. It could be used alongside with 202205251604#.

  • Git
#git #graph