push 的时候之后上传当前分支,并不会上传 HEAD;远程仓库的 HEAD 是永远指向默认分支(即 master)的。push 的时候只会上传当前的 branch 的指向,并不会把本地的 HEAD 的指向也一起上传到远程仓库。
1 2 3 4 5 6 7 8
$ git-exercise git:(main) git push 只能在main上简写。 $ git-exercise git:(sami) git push origin sami ~ remote: Create a pull request for'sami' on GitHub by visiting: remote: https://github.com/cutegentle/git-exercise/pull/new/sami To github.com:cutegentle/git-exercise.git * [new branch] sami -> sami
$ git-exercise git:(main) git checkout 128b Note: switching to '128b'.
You are in'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 128b182 Initial commit 恢复: $ git-exercise git:(128b182) git checkout main Previous HEAD position was 128b182 Initial commit Switched to branch 'main' Your branch is up to date with 'origin/main'.
checkout 和 reset 的不同
checkout 和 reset 都可以切换 HEAD 的位置,它们除了有许多细节的差异外,最大的区别在于:reset 在移动 HEAD 时会带着它所指向的 branch 一起移动,而 checkout 不会。当你用 checkout 指向其他地方的时候,HEAD 和 它所指向的 branch 就自动脱离了。