简体   繁体   English

致命:您当前不在分支上。git push master HEAD:<name-of-remote-branch>

[英]fatal: You are not currently on a branch.git push master HEAD:<name-of-remote-branch>

I am facing git issue following below...我在下面面临 git 问题...

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

git push master HEAD:<name-of-remote-branch>

What shall I do?我该怎么办?

If you are sure that you on the correct commit locally , then you can just do:如果您确定您在本地提交正确,那么您可以执行以下操作:

git push origin HEAD:master --force

And then, importantly, change your pointer from the detached head to the current head by:然后,重要的是,通过以下方式将指针从分离的头部更改为当前的头部:

git branch --force master HEAD
git checkout master

This assumes that you have done the following steps if you wanted to revert to a previous commit which is named "target commit" in the following (as "previous commit" is ambiguous, it could be any previous commit):如果您想恢复到先前名为“目标提交”的提交(因为“先前提交”不明确,它可以是任何先前的提交),则假设您已完成以下步骤:

git reset --hard <target commit>

You have checked out the code of that commit by:您已通过以下方式签出该提交的代码:

git checkout <target commit>

If that gives you:如果这给你:

Warning: you are leaving 1 commit behind, not connected to
any of your branches:

<unknown commit> revert to <target commit>

THEN do the git reset command above again!然后再次执行上面的git reset命令!

IF git status says:如果git status说:

HEAD detached at <target commit>
nothing to commit, working tree clean

THEN you are ready to push with the command above:然后你就可以用上面的命令推送了:

git push origin HEAD:master --force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM