为什么checkout -b仅在第二次尝试后才能正常工作? [英] Why checkout -b does work only after second attempt?
本文介绍了为什么checkout -b仅在第二次尝试后才能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$sudo git clone sample.git
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.
done.
$ cd sample
$ echo "hello world" > readme
$ git add readme
$ git checkout -b a
Switched to a new branch 'a'
$ git branch
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
$ git checkout a
error: pathspec 'a' did not match any file(s) known to git.
$ git checkout -b b
Switched to a new branch 'b'
$ git branch
$ git commit -am .
[b (root-commit) 12b8434] .
1 file changed, 1 insertion(+)
create mode 100644 go
$ git branch
* b
$ git checkout a
error: pathspec 'a' did not match any file(s) known to git.
$ git checkout -b a
Switched to a new branch 'a'
$ git branch
* a
b
我的第一个结帐-ba
有什么问题,为什么分支未创建?
What was wrong with my first checkout -b a
, why the branch was not created?
推荐答案
好的,您告诉 git
来创建一个空仓库中的分支。还没有提交,分支只是一个指向提交的粘滞便笺。那么,什么是 git
应该做...
Well, you told git
to create a branch in an empty repository. There is no commit yet, and a branch is just a "sticky note" pointing to a commit. So what is git
supposed to do...
至少它将您的新分支存储在 HEAD
,所以分支提示将被更新为将来的提交。如您的提交所示。
At least it stores your new branch in HEAD
, so the branch tip will be updated with future commits. As shown by your commit.
更多有趣的空白存储库:
More fun with empty repositories:
~/tmp> mkdir empty
~/tmp> cd empty
~/tmp/empty> git init
Initialized empty Git repository in tmp/empty/.git/
~/tmp/empty> git log
fatal: bad default revision 'HEAD'
~/tmp/empty> git branch xxx
fatal: Not a valid object name: 'master'.
~/tmp/empty> git checkout -b xxx
Switched to a new branch 'xxx'
~/tmp/empty> git log
fatal: bad default revision 'HEAD'
~/tmp/empty> ls -l .git/
branches/ config description HEAD hooks/ info/ objects/ refs/
~/tmp/empty> cat .git/HEAD
ref: refs/heads/xxx
~/tmp/empty> ls -l .git/refs/heads
total 0
编辑: @ jthill。
adopted the comment from @jthill.
这篇关于为什么checkout -b仅在第二次尝试后才能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文