threads / bug / 54168

Bug Report: "git reset --hard" does not cancel an on-going rebase

Subject: Bug Report: "git reset --hard" does not cancel an on-going rebase

## tl;dr

2 messages between Aug 31, 2020 and Aug 31, 2020.

replies: 1people: 2as markdown or json

Thomas Bétous· Aug 31, 2020, 21:59 UTC · lore
Hello,

I would like to report an inconsistent behavior of the rebase/reset commands. I don’t know whether it is an actual bug or something else but according to me something is not right. When a rebase gets paused (because of a conflict for instance) I would expect the command "git reset --hard" to cancel this on-going rebase but it does not. I expect this because for instance "git reset --hard" cancels a cherry-pick in the same use case so I think the behavior of these 2 commands should be consistent.

The issue can be reproduced with the following commands: # First trigger a rebase that will paused because of a conflict # (there is probably a simpler way to end up in this use case) $ git init test-repo-rebase-reset $ cd test-repo-rebase-reset/ $ touch file $ git add file $ git commit file -m 'First commit’ $ echo "dummy line" > file $ git commit --all -m 'Second commit’ $ git switch --create new-branch HEAD~1 $ git rm file $ git commit -m 'Remove file’ $ git rebase master # Let’s check that the rebase got paused because of the conflict $ git status $ git reset --hard # Even after the “git reset --hard“ the rebase was not aborted $ git status # Now let’s check what happens with the cherry-pick command $ git rebase --abort $ git switch master $ git cherry-pick $(git rev-parse -1 new-branch) # The cherry-pick got paused because of the same conflict git status # Let’s try to abort the cherry-pick with the reset command git reset --hard # Double check the cherry-pick was aborted git status

I think the behavior will be the same on all OS but if it helps I was able to reproduce it on Cygwin/Windows 10 with git 2.28.0 and Mac OS with git 2.26.0
Note that in the commands above I didn’t give any revision to the reset command but the issue would be the same if I did. Moreover it makes it even more confusing I think: you can move your HEAD to any revision while the rebase is still waiting to be completed.
What do you think? Does this behavior seems normal to you?
Thank you in advance for your answer.
Best regards,
Thomas
Junio C Hamano· Aug 31, 2020, 23:11 UTC · re: Thomas Bétous · lore

Re: Bug Report: "git reset --hard" does not cancel an on-going rebase

Thomas Bétous <th.betous@gmail.com> writes:
Show 9 quoted lines
> I would like to report an inconsistent behavior of the
> rebase/reset commands. I don’t know whether it is an actual bug
> or something else but according to me something is not right.
> When a rebase gets paused (because of a conflict for instance) I
> would expect the command "git reset --hard" to cancel this
> on-going rebase but it does not.  I expect this because for
> instance "git reset --hard" cancels a cherry-pick in the same use
> case so I think the behavior of these 2 commands should be
> consistent.

It is reasonable and desirable for multi-commit operations like "rebase", "cherry-pick A..B" and "revert A..B" not to abort the entire sequence with a mere "reset --hard". After a step resulted in conflicts, the user may try to resolve them, getting into too deep a hole by botching resolution, and wish to redo the current step from scratch, and "reset --hard" can be a way to clean the slate before recreating the same conflict. To abort the whole thing, "rebase --abort" and "cherry-pick --abort" would be needed to differentiate from the "clean this single step" request made with "reset --hard".

On the other hand, operations on a single commit like "cherry-pick X" does not have to retain "what to do after we have dealt with the current step", so "reset --hard" that finishes the whole thing (after all, the whole thing is the single step that may have conflicted) would just be a convenient short-hand.

← back to recent threads