git rebase -i和壁球无法分离HEAD [英] git rebase -i with squash cannot detach HEAD
问题描述
使用最新的git(2.1.0.24
),每当我尝试git rebase -i
到squash
进行某些提交时,压扁都无法detach HEAD
状态.我希望它可以压缩提交内容,并按预期将我重新回到分支机构.没有未暂存的文件,我的工作树中的更改或任何隐藏的内容.为什么要这样做?
Using the latest git (2.1.0.24
), whenever I try to git rebase -i
to squash
some commits, the squash cannot detach HEAD
state. I expect it to squash the commits and put me back on my branch as I expected. There are no unstaged files, changes in my working tree, or anything in the stash. Why is it doing this?
> [master] » git rebase -i HEAD~3
(我压缩了一些提交)...
(I squash a few commits)...
pick c9e9b62 Fixes super important bug #123.
squash c0dc9f9 wip
pick 5385a37 wip2
# Rebase fb83e59..5385a37 onto fb83e59
(然后它给了我)
Note: checking out 'c9e9b62'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at c9e9b62... Fixes super-important bug #123.
could not detach HEAD
它似乎可以成功恢复基准,但是由于某种原因,它不会让我回到分支机构.
It appears to rebase successfully, but for some reason won't put me back on the branch.
> [c9e9b62] » git rebase --continue
No rebase in progress?
尝试重新设置基准之前的git graph日志:
git graph log BEFORE the rebase attempt:
* 5385a37 (HEAD, master) wip2
* c0dc9f9 wip
* c9e9b62 Fixes super-important bug #123.
* ff80ed9 random commit msg
* 1f407d5 random commit msg
...
* ef106db random commit msg
* 6c244ef Merge branch 'sentences'
|\
| * a641cbf (origin/sentences) random commit msg
| * bfe8eae random commit msg
| ...
重新尝试后的git graph日志:
git graph log AFTER the rebase attempt:
* c9e9b62 (HEAD) Fixes super-important bug #123.
* ff80ed9 random commit msg
* 1f407d5 random commit msg
...
* ef106db random commit msg
* 6c244ef Merge branch 'sentences'
|\
| * a641cbf (origin/sentences) random commit msg
| * bfe8eae random commit msg
| ...
推荐答案
消息could not detach HEAD
来自交互式rebase脚本,特别是在此处:
The message could not detach HEAD
comes from the interactive rebase script, specifically right here:
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
output git checkout $onto || die_abort "could not detach HEAD"
git update-ref ORIG_HEAD $orig_head
do_rest
这里令人好奇的部分是git checkout $onto
步骤似乎已经成功:在失败之前,您得到了:
The curious part here is that the git checkout $onto
step appears to have succeeded: right before the failure, you got:
HEAD is now at c9e9b62... Fixes super-important bug #123.
作为输出,来自于发生在这里的git checkout
.然后,git checkout
在看起来很成功之后,显然退出了非零值,就好像它失败了一样.这会调用die_abort
,从而终止了重新设置基准的尝试.
as output, and that's from the git checkout
that happened here. Then, after apparently succeeding, git checkout
apparently exited non-zero as if it had failed. This invoked die_abort
which terminated the rebase attempt.
现在, 文档声明一个结帐后钩子
Now, the documentation claims that a post-checkout hook
不能影响 git checkout 的结果.
但是,在 source 中,在switch_branches
底部附近,我们有:
However, in the source, near the bottom of switch_branches
, we have:
ret = post_checkout_hook(old.commit, new->commit, 1);
free(path_to_free);
return ret || writeout_error;
其中post_checkout_hook
运行结帐后挂钩并获取其退出代码.因此,git checkout
在这里似乎有两种返回失败状态的方法:写树时出错(例如,磁盘已满),或者您有一个check-out钩子并且退出了非零值.后者似乎更有可能. (而且,我对此进行了测试,实际上确实导致结帐失败".由于源使用||
,因此该钩子中任何非零出口都将变为git checkout
本身的出口状态.)
where post_checkout_hook
runs the post-checkout hook and grabs its exit code. So there appear to be two ways for git checkout
to return a failure status here: either there's an error writing the tree (e.g., the disk has filled up), or you have a post-checkout hook and it is exiting non-zero. The latter seems more likely. (And, I tested this and it does in fact cause the checkout to "fail". Since the source uses ||
, any nonzero exit in the hook turns into an exit status of 1 for git checkout
itself.)
您有结帐后挂钩吗?如果是这样,它将做什么?
Do you have a post-checkout hook? If so, what does it do?
(尚不清楚此处是文档或git checkout
命令中的哪个错误,但至少有一个错误.我想可能是文档,它应该说更多类似不能影响
(It's not clear which is wrong here, the documentation or the git checkout
command, but at least one is wrong. I'd say probably the documentation, which should say something more like "cannot affect the files that git checkout
will write, but can make the command itself return a failure status".)
这篇关于git rebase -i和壁球无法分离HEAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!