Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase --continue and --stepback?

Tags:

git

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

like image 656
elmarco Avatar asked May 02 '11 11:05

elmarco


People also ask

What does git rebase -- continue does?

Git gets to the edit dd1475d operation, stops, and prints the following message to the terminal: You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue. At this point, you can edit any of the files in your project to make any additional changes.

What is the difference between revert and rebase in git?

'revert' means to add more commits to make the code look like it did at a different commit, but the history is different (the history includes the old state and the path back to the different state). rebase doesn't change the code at all, but just changes the history.

How do I force git to rebase continue?

When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To check out the original branch and stop rebasing run "git rebase --abort".


1 Answers

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^

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

like image 94
Moberg Avatar answered Sep 22 '22 18:09

Moberg