git rebase --continue and --stepback?

Git

Git Problem Overview


Is there a way to step back a commit during an interactive rebase?

Git Solutions


Solution 1 - Git

Yes there is. How to step back during an interactive rebase:

  1. Get the commit hash of your current HEAD, for example with git rev-parse HEAD
  2. run git rebase --edit-todo
  3. insert a pick with that hash to the top of that file pick <hash from step 1>
  4. run git reset --hard HEAD^ (this is a hard reset so if you have done anything you want to keep make sure to store it somewhere e.g. git stash before you run the command)

Now you are still in the rebase but one commit back and you are free to continue rebasing with

  1. git rebase --continue.

If you don't want the undone commit to be picked straight up without edits you can add edit <HASH> instead of pick <HASH> to the todo list (step 3).

Addendum: You can remember more hashes, reset to an even earlier point and add multiple picks to redo more than one commit.

Idea from: http://arigrant.com/blog/2014/5/4/git-rebase-stepping-forward-and-back

Solution 2 - Git

Actually you can even if you're not doing interactive rebase.

As johnb003 mentioned in his comment, when rebasing, you're really making a series of new commits. By doing something such as git log --pretty=oneline --abbrev-commit, you can easily see all the commits you've already made through the rebase. Simply copy their hashes for easy reference later.

Then git rebase --abort, git rebase -i <base_branch>, copy the hashes you want to preserve, possibly change them to edit if you want to modify any of them, and continue

Solution 3 - Git

Nope, as Magnus said.

However,

  • git-rerere could come close to what you want in a way: if there were previous manual conflict resolutions that you didn't want to loose, you can enable rerere (prerecorded conflict resolutions) so that they will automatically be resolved in the same way on subsequent merges. Note that this means that you'll have to remember what part you want to resolve differently next time (presumably the goal of having a step-back in the first place?) because - well, rerere assumes you want to applies the same resolution again.

If you look at the implementation of rebase, you might be able to figure out alternative settings for GIT_WORK_TREE/GIT_DIR/GIT_INDEX; You could then perhaps use plumbing commands with a reflog for the rebase-in-progress branch?

  • this takes you deep into undocumented internals (beyond the plumbing)
  • you might just as well propose a patch to rebase that implements --step-back

Solution 4 - Git

No. You can --continue to continue rebasing (e.g. after you have solved some conflict), --abort (undo and whole rebase process) or --skip to skip current patch.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionelmarcoView Question on Stackoverflow
Solution 1 - GitMobergView Answer on Stackoverflow
Solution 2 - GitjunvarView Answer on Stackoverflow
Solution 3 - GitseheView Answer on Stackoverflow
Solution 4 - GitralphtheninjaView Answer on Stackoverflow