gpt4 book ai didi

git rebase -i with squash 无法分离 HEAD

转载 作者:太空狗 更新时间:2023-10-29 13:17:38 24 4
gpt4 key购买 nike

使用最新的 git (2.1.0.24),每当我尝试 git rebase -isquash 一些提交时,squash 不能分离 HEAD 状态。我希望它能压缩提交并按我的预期让我回到我的分支。没有未暂存的文件、工作树中的更改或存储中的任何内容。为什么要这样做?

> [master] » git rebase -i HEAD~3

(我压缩了一些提交)...

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

它似乎成功地 rebase 了,但出于某种原因不会让我回到分支上。

> [c9e9b62] » git rebase --continue
No rebase in progress?

rebase 尝试前的 git 图日志:

* 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
| ...

rebase 尝试后的 git 图日志:

* 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 脚本,特别是在这里:

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 步骤似乎已经成功:就在失败之前,您得到了:

HEAD is now at c9e9b62... Fixes super-important bug #123.

作为输出,它来自此处发生的 git checkout。然后,在显然成功之后,git checkout 显然以非零值退出,就好像失败了一样。这调用了终止 rebase 尝试的 die_abort

现在,documentation claims checkout 后 Hook

cannot affect the outcome of git checkout.

但是,在 source 中,靠近 switch_branches 的底部,我们有:

    ret = post_checkout_hook(old.commit, new->commit, 1);
free(path_to_free);
return ret || writeout_error;

post_checkout_hook 运行 checkout 后 Hook 并获取其退出代码。所以 git checkout 似乎有两种方法在这里返回失败状态:写入树时出错(例如,磁盘已满),或者你有一个 post-checkout hook 和它退出非零。后者似乎更有可能。 (而且,我对此进行了测试,它确实会导致 checkout “失败”。由于源代码使用 ||,因此 Hook 中的任何非零退出都会变成 的退出状态 1 git checkout 本身。)

你们有 checkout 后 Hook 吗?如果是,它有什么作用?

(这里不清楚哪个是错误的,是文档还是 git checkout 命令,但至少有一个是错误的。我想说可能是文档,它应该说的更像是“不能影响 git checkout 将写入的文件,但可以使命令本身返回失败状态。)

关于git rebase -i with squash 无法分离 HEAD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25561485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com