[英]Git - moving back and forth and getting fatal: You are not currently on a branch?
前后移动以跟踪我的存储库中的错误后,例如:
$ git reset --hard fcf9818
找到了错误,然后我想继续进行最新的提交,例如:
$ git checkout 32764bf
然后,我开始进行更改并想要提交:
$ git status
HEAD detached at 32764bf
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
我以为我已经是最新提交了?
但是我继续承诺:
$ git add -A
$ git commit
[detached HEAD ccf8009] Fixed gird bug on Safari - removing bootstrap grid css. Added code to centralise the image.
2 files changed, 6 insertions(+), 1 deletion(-)
现在我有这个错误:
$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
如果要在后退后转发到最新提交,应该怎么做呢?
我现在该如何解决错误?
编辑:
$ git checkout 32764bf
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
6015d59 Fixed gird bug on Safari - removing bootstrap grid css. Added code to centralise the image.
If you want to keep it by creating a new branch, this may be a good time
to do so with:
git branch <new-branch-name> 6015d59
HEAD is now at 32764bf... Added template for finally - only image.
而且我仍然HEAD detached at 32764b
:
$ git status
HEAD detached at 32764bf
nothing to commit, working tree clean
如果您签出了修订版本(不是分支)并从那里进行了更正,则您处于分离的HEAD状态。 为了推送到远程分支,您可以创建一个分支并将其推送到远程,也可以(如消息中所述)推送以指定要推送到的远程分支:git push a-remote HEAD:remote-branch -名称
假设有一个分支主节点,它指向一个提交32764bf 。
git checkout master
现在您在分支机构主管中。 当您进行新的提交时,引用母版将移至新的提交。 ref HEAD也是如此。 当您运行git reset --hard <commit>
,master和HEAD都将移至该提交。 git push
意味着git push origin master:master
,等效于git push origin HEAD:master
。
git checkout 32764bf
现在,您处于独立的头上。 将其作为无名分支,这是新手。 当您进行新提交时,HEAD移至新提交,但master仍指向32764bf。 当您运行git reset --hard <commit>
。 只有HEAD移动到该提交,而master保持不动。 git push
不能暗示git push origin master:master
因为您现在不在分支master上。 假设现在HEAD指向8977abf。 您可以运行git push origin HEAD:master
或git push origin 8977abf:master
来更新远程存储库中的master,但本地master不变,仍指向32764bf。 显然,这两个推送与git push origin master:master
或git push origin 32764bf:master
因为现在HEAD和master指向不同的提交。 即使现在HEAD和master指向同一提交,位于分离的HEAD和位于分支master上的状态也是两种不同的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.