我有两种不同的方式让git告诉我当前的分支:
git rev-parse --abbrev-ref HEAD
Run Code Online (Sandbox Code Playgroud)
和
git symbolic-ref --short HEAD
Run Code Online (Sandbox Code Playgroud)
呃......两者究竟做了什么,何时会有所不同,如果有的话?
Leo*_*eon 11
它们在分离的HEAD状态下表现不同(当没有当前的命名分支时).在这种情况下HEAD
,不是符号引用并且git symbolic-ref
以错误退出,而是自行git rev-parse --abbrev-ref
解决HEAD
.
$ git checkout HEAD^
Note: checking out 'HEAD^'.
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 performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at bb2d3b1... fix layout with extra newline
$ git symbolic-ref --short HEAD
fatal: ref HEAD is not a symbolic ref
$ git rev-parse --abbrev-ref HEAD
HEAD
Run Code Online (Sandbox Code Playgroud)
您可能还想查看git命令name-rev.即使处于分离状态,git也会尽力确定你所在的分支
$ git name-rev --name-only HEAD
master~1
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
561 次 |
最近记录: |