由于detached Head而导致everything up-to-date,无法push

写代码时因为request的url错误,导致报错"undefined token o"。当时为了查找错误原因,用git checkout <之前的commit hash>回滚。


找到错误之后,以为再用git checkout回滚到最新的commit就没事了。回滚到最新commit之后,有commit新代码,commit之后出现[detach HEAD]之类的信息,没当回事(后来知道这是主要原因),继续push,但是push的结果是cmd显示everything up-to-date,无法将最新的代码push到remote repo。最后上网找到了这个:

http://stackoverflow.com/a/1000009/2177408

You would not be working with a detached head by any chance ?

As in:

detached head

indicating that your latest commit is not a branch head.

$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>

As mentioned in the git checkout man page (emphasis mine):

It is sometimes useful to be able to checkout a commit that is not at the tip of one of your branches.
The most obvious example is to check out the commit at a tagged official release point, like this:

$ git checkout v2.6.18

Earlier versions of git did not allow this and asked you to create a temporary branch using the -boption, but starting from version 1.5.0, the above command detaches your HEAD from the current branch and directly points at the commit named by the tag (v2.6.18 in the example above).

You can use all git commands while in this state.
You can use git reset --hard $othercommit to further move around, for example.
You can make changes and create a new commit on top of a detached HEAD.
You can even create a merge by using git merge $othercommit.

The state you are in while your HEAD is detached is not recorded by any branch (which is natural --- you are not on any branch).
What this means is that you can discard your temporary commits and merges by switching back to an existing branch (e.g. git checkout master), and a later git prune or git gcwould garbage-collect them.
If you did this by mistake, you can ask the reflog for HEAD where you were, e.g.

$ git log -g -2 HEAD




http://stackoverflow.com/a/896956/2177408

Looks you need to put that commit back into the master branch (if it belongs there). Also it looks like you’ve detached HEAD because that commit is not a branch head. If all this is true, try the following:

# git log -1

Remember the commit ID.

# git checkout master
# git reset --hard <commit-id>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值