当从分离的头部切换回分支时,Git“保持遗留”

时间:2012-11-20 19:09:15

标签: git

对于我们仓库中的某些提交(但不是全部),如果我检查提交,然后返回到主分支,我会收到一个意外的警告,告知提交被遗忘:

# 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'

所有提交的提交(据我所知)都可以从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错误?虽然我没有看到发行说明中看起来相关的任何内容......

1 个答案:

答案 0 :(得分: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的提交。请注意,我们正在执行与通常的二分相反的操作,在该二分中,您尝试查找引入错误的提交。