git - What should RESETING detached HEAD to BRANCH do? -
if understand right, when have detached head(head->commit), git checkout branch solves issue(head->branch[->somecommit])
but resetting branch do? supposed set pointer of object(often branch) head points branch. since dont have middle-man (branch) - then? , why?
it moves head: mentioned in "practical uses of git reset --soft?":
git resetmoving head.
if move head commit, head remains detached.
after a discussion difference between git reset , git checkout vs detached or attached nature of symbolic reference head, here found together:
- if head points on branch,
git resetmove branch<something>: resetting doesn't make un-detached, changes branch head - if head points on commit (was detached), remain detached: op puts it:
so when detached , call
git reset <branch>finds commit behind branch , change commit in.git/headcommit<branch>refers to.
let's consider head attached branch1 (cat .git/head return branch1):
git checkout branch2change headbranch2, leavebranch1untouchedgit reset branch2resetbranch1headbranch2:cat .git/refs/heads/branch1contains same sha1branch2.
that's difference:
- reset moves head (as told @ beginning: moving head)
- checkout switches branches (or detaches head)
regarding attached/detached nature of head:
- reset doesn't change nature of head (if attached, remains attached)
- checkout can change nature of head (if attached , checkout commit instead of branch, head becomes detached)
Comments
Post a Comment