git fetch的奇怪行为

时间:2011-02-23 18:05:13

标签: git fetch commit rebase git-checkout

GIT fetch我遇到了一个大问题......看看这个

$ git fetch
From server:project
   422b4cb..a04c062  master     -> origin/master

$ git show-ref
ba113be885e66a5306d1646cd3db0801170c04f8 refs/heads/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/master
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/test
a04c062261beeb4a951337ebb58745945cac3562 refs/remotes/origin/HEAD
ba113be885e66a5306d1646cd3db0801170c04f8 refs/remotes/origin/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/remotes/origin/master

另一个git fetch

$ git fetch
From server:project
 + a04c062...422b4cb HEAD       -> origin/HEAD  (forced update)

$ git show-ref
ba113be885e66a5306d1646cd3db0801170c04f8 refs/heads/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/master
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/test
422b4cbac3db2784c8f6e94ffd99c7afcda9122d refs/remotes/origin/HEAD
ba113be885e66a5306d1646cd3db0801170c04f8 refs/remotes/origin/alpha-release
422b4cbac3db2784c8f6e94ffd99c7afcda9122d refs/remotes/origin/master

另一个......

$ git fetch
From server:project
   422b4cb..a04c062  master     -> origin/master

$ git show-ref
ba113be885e66a5306d1646cd3db0801170c04f8 refs/heads/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/master
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/test
a04c062261beeb4a951337ebb58745945cac3562 refs/remotes/origin/HEAD
ba113be885e66a5306d1646cd3db0801170c04f8 refs/remotes/origin/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/remotes/origin/master

另一个git fetch

$ git fetch
From server:project
 + a04c062...422b4cb HEAD       -> origin/HEAD  (forced update)

$ git show-ref
ba113be885e66a5306d1646cd3db0801170c04f8 refs/heads/alpha-release
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/master
a04c062261beeb4a951337ebb58745945cac3562 refs/heads/test
422b4cbac3db2784c8f6e94ffd99c7afcda9122d refs/remotes/origin/HEAD
ba113be885e66a5306d1646cd3db0801170c04f8 refs/remotes/origin/alpha-release
422b4cbac3db2784c8f6e94ffd99c7afcda9122d refs/remotes/origin/master

我的refs/remotes/origin/HEADrefs/remotes/origin/master始终强制更新为422b4cb ...

发生什么事了? 422b4cb ...是一个旧提交。

3 个答案:

答案 0 :(得分:12)

哇...在与GIT的一场大战之后,我使用了解决这个问题:

git push origin :HEAD

答案 1 :(得分:4)

我看到这种行为的唯一其他情况是this thread

  

看起来你在远程方面有本地分支“HEAD”(不是特殊引用HEAD),这会弄乱它。

     存储库中的

ls-remote显示“refs/heads/HEAD”,右侧(还有HEAD,这是必需的特殊参考号)?

当引入名为“422b4cb”的分支时,可能会提交HEAD吗?

注意(7年后):无论如何都要Git 2.16 (Q1 2018), you won't be able to create a branch named HEAD

答案 2 :(得分:1)

我不确定导致此问题的原因,但是如果你有对git存储库的shell访问权限,你可以修复它:

$ [ ... log into shell on git server ...]
$ cd /path/to/repo.git
$ rm refs/heads/HEAD

相同
$ git push origin :HEAD

在工作副本中。在我的情况下,我们将repo设置为拒绝删除分支,因此在这种情况下我必须登录并手动执行。