2012-11-20 90 views
4

对于我们的回购库中的某些提交(但不是全部),如果我签出提交,然后返回到主分支,我会收到意外的警告犯下被抛在后面:Git“commit left behind”when turn back to a branch from detached head

# Check out one of the commits in question: 
$ git checkout dd33caa5b004b0e3bd449152f9335e40450db91c 
Note: checking out 'dd33caa5b004b0e3bd449152f9335e40450db91c'. 

You are in 'detached HEAD' state. You can look around, make experimental 
[...] 
HEAD is now at dd33caa... Organized DataStore build files, added cleanup targets. 

# Now switch back to the master branch so I can work: 
$ git checkout master 
Warning: you are leaving 17 commits behind, not connected to 
any of your branches: 

    dd33caa Organized DataStore build files, added cleanup targets. 
    4916eec Fixes to C++ codegen to use maven features. 
    a26291d Merge branch 'master' of [redacted origin repo address] 
    93ae0b9 Add protobuf 2.4.1 jar file to install scripts. Add QTDIR to build script. 
... and 13 more. 

If you want to keep them by creating a new branch, this may be a good time 
to do so with: 

git branch new_branch_name dd33caa5b004b0e3bd449152f9335e40450db91c 

Switched to branch 'master' 

所有问题提交(据我可以告诉)是从主可达,而在分离的头的状态(这是一个干净的克隆我还没有做出任何承诺我们的仓库)。主分公司的历史记录如下所示:

* 04d7fcc (HEAD, origin/master, origin/HEAD, master) Removed files from DataS 
* ecaa2f5 Fixed .gitignore. 
* dd33caa Organized DataStore build files, added cleanup targets. 
* 4916eec Fixes to C++ codegen to use maven features. 
* a26291d Merge branch 'master' of [redacted] 
|\ 
| * 93ae0b9 Add protobuf 2.4.1 jar file to install scripts. Add QTDIR to buil 
| * 3cba845 switched to protobug 2.4.1 jar files 
| * 1046d22 fixed GATEWAY_ROOT 
| * ebcda06 edit windows build scripting path for new repo location 
| * bda1e17 add windows build scripts from old repo 
* | 371883d Merge branch 'master' of [redacted] 
|\ \ 
| |/ 
| * 771c579 Fix MCast and RMCast service names in gateway manager config 
* | 864fb25 First cut at DataStore code generation update to sync with refact 
|/ 
* f505e46 Testing new repository 
* 111d89a Merge branch 'master' of [redacted] 

任何想法可能会发生什么吗?它似乎与一个特定用户的提交相关联,我可以在OSX上使用Git 1.7.9.6并在Ubuntu上使用Git 1.7.9.5,但在Ubuntu上使用1.8.0而不能使用它......因此,可能是Git错误?我没有在版本说明中看到任何看起来相关的东西,尽管...

+2

'dd33caa'实际上是'ecaa2f5'的父提交吗?我知道它看起来像这样,但是当你做'git log --graph --pretty = oneline --all'时,孤立分支('git checkout --orphan newbranch')就会出现这种情况... – twalberg

+0

是的,但是(由于此评论表的局限性,不能向您显示)。 – JonathonW

+0

嗯....不知道其他“正常”的情况下会导致这种情况,所以往往表明一个错误... – twalberg

回答

5

是的,这看起来像是一个Git bug。如果你想知道什么修复了它,你可以做一个二分法。克隆git.git,检出一个版本即碎,并确认出现问题,了解最新,并验证它的固定,然后运行二分法查找其呈交解决了这一问题:

$ git clone git://github.com/git/git.git 
$ cd git 
$ git checkout v1.7.9.5 
$ make 
$ (cd my-repo && /path/to/my/git checkout dd33caa && /path/to/my/git checkout master 2>&1 | grep "leaving .* commits behind") 
$ git checkout v1.8.0 
$ make 
$ (cd my-repo && /path/to/my/git checkout dd33caa && /path/to/my/git checkout master 2>&1 | grep "leaving .* commits behind") 
# if the above gave the expected results: 
$ git bisect start v1.7.9.5 v1.8.0 
$ git bisect run bash -c "make && cd my-repo && /path/to/my/git checkout dd33caa && (! /path/to/my/git checkout master 2>&1 | grep -q 'leaving .* commits behind')" 

这应该离开你在修复你的bug的提交上。请注意,我们正在进行与通常的二分法相反的操作,其中您正试图找到引入错误的提交。

+1

是的,发现了错误及其修复。这是一个报告错误,如果先前在分离的HEAD中的提交只能通过符号引用指向的提交来实现...该错误已在[add416a](https://github.com/ git/git/commit/add416a6c05b580e005726f318463698d746384d),早在六月份。 – JonathonW

+0

@JonathonW:这个bug在[add416a](https://github.com/git/git/commit/add416a6c05b580e005726f318463698d746384d)中修复,该版本在Git v1.7.11.5版本中发布。 – Flimm

相关问题