Git:提交冲突和提交回滚

时间:2019-05-10 21:39:47

标签: git collision

  1. 当我请求日志时:
  

MacBook-Pro-nnuttertools:program $ git log

我收到:

commit f2504e036044... (HEAD -> master, f2504e036044...)

Author: Nnuttertools <nnuttertools@gmail.com>

Date:   Mon Apr 29 00:12:00 2019 +0300

    CommitName

2。然后我想将状态保存在存储中并切换到提交:

  

MacBook-Pro-nnuttertools:程序$ git stash

     

MacBook-Pro-nnuttertools:程序$ git checkout f2504e036044 ...

但是第一个命令抛出错误:

warning: refname 'f2504e036044...' is ambiguous.
Git normally never creates a ref that ends with 40 hex characters
because it will be ignored when you just specify 40-hex. These refs
may be created by mistake. For example,

  git checkout -b $br $(git rev-parse ...)

where "$br" is somehow empty and a 40-hex ref is created. Please
examine these refs and maybe delete them. Turn this message off by
running "git config advice.objectNameWarning false"

并且代码未还原。但是较早的提交可以做到这一点。 我需要使用什么来解决冲突?不幸的是,我没有时间弄清楚。现在的主要目标是返回正确的代码。

1 个答案:

答案 0 :(得分:3)

您在这里所做的是创建一个与对象同名的分支。 Git通常假定一个40个字符的十六进制名称是一个对象ID,但在这种情况下,它也是一个分支。很困惑,所以它告诉您您要的内容是不明确的。

最简单的解决方案是临时签出其他分支,然后删除名称不正确的分支,然后签出所需的修订版。因此,如下所示:

$ git checkout -b temp
$ git branch -D LONG-HEX-NAME
$ git branch checkout LONG-HEX-NAME
$ git branch -D temp