Mastering Git - Crafting History With Rebase

© 2012 - 2015 thoughtbot, inc. Upcase, the design of a robot, and thoughtbot are registered trademarks of thoughtbot, inc.

This is a companion discussion topic for the original entry at

how can one rebase a range of commits?

I tried:

git rebase -i c5f15a8..d861268

but that doesn’t seem to work.

I thought checking out the last commit of the range would possibly help, but I of course end up in a detached HEAD state. If the range of commits are within the history of the current branch you could just do an interactive rebase back to the earliest of the desired range of commits and only make changes within the range of commits. Any commits after that range would remain unchanged if they aren’t modified during the rebase. Would that work for what you had in mind?

I believe you both need to be on a branch (not a detached head state), and can only provide the base commit with the other commit being the current HEAD commit.

While it theoretically could work with the range, you’d end up in a detached head state pointing to the new commit(s) created via the rebase. Git seems to enforce already having a branch to point at the new commits.

I have quite a hard time manually editing hunks with
git add --patch
whatever change I make, it is not applied once I quit the text editor (wether I use :wq or :x like in the video) and I’m asked to make the same choice again:

-def greet(name)
-  puts "Hello, #{name}"
Stage this hunk [y,n,q,a,d,/,e,?]?

How can I exit the editor properly ?