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 reset moving 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 reset move 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/head commit <branch> refers to.

let's consider head attached branch1 (cat .git/head return branch1):

  • git checkout branch2 change head branch2 , leave branch1 untouched
  • git reset branch2 reset branch1 head branch2: cat .git/refs/heads/branch1 contains same sha1 branch2.

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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -