Git rebase -i with squash cannot detach HEAD

Using the last git ( 2.1.0.24), whenever I try to execute git rebase -ibefore squash, some commits, squash cannot detach HEAD. I expect it to crush the commits and put me back in its branch as I expected. There are no uninstalled files, changes in my working tree or anything in the dash. Why is he 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 

(Then it gives me)

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 seems that it has been successfully restored, but for some reason will not return the branch to me.

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

git graph log BEFORE the recovery task:

* 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 log AFTER SEQUENCE:

* 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
| ...
+4
source share
3 answers

could not detach HEAD rebase script, :

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, -, , . die_abort, .

,

git.

, switch_branches, :

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

post_checkout_hook . , git checkout : (, ), , , . ( , "". ||, 1 git checkout.)

? , ?

(, , git checkout, . , , , - , " , git checkout , ".)

+9

, , , . , if:

if false
  command-that-exits-with 0
else
  command-that-exists-with 5
  # hook will exit with 5
end

# EOF

script , . :

$ .git/hooks/post-checkout
doing stuff!
$ echo $?
5

exit 0 script, et voilà.

0

, ... . , :

HASH2 change line in file b
HASH1 rename file a to b

, , HASH1 . HASH2 HASH1, could not detach HEAD.

Of course, this seems obvious here, but in a longer real example, when multiple commits and squashes are reset, you can miss this type of inconsistency !!

0
source

All Articles