I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my
There's a faster version if you only want to extract content from just one file. It's faster because the interactive rebase is not actually interactive anymore (and it's of course even faster if you want to extract from the last commit, then no need to rebase at all)
the_file
. Close the_file
. That's the only edition you need, all the rest is just git commands.Stage that deletion in the index:
git add the_file
Restore the lines you just deleted back into the file without affecting the index!
git show HEAD:./the_file > the_file
"SHA1" is the commit you want to extract the lines from:
git commit -m 'fixup! SHA1'
Create the second, brand new commit with the content to extract restored by step 3:
git commit -m 'second and new commit' the_file
Don't edit, don't stop/continue - just accept everything:
git rebase --autosquash -i SHA1~1
Of course even faster when the commit to extract from is the last commit:
4. git commit -C HEAD --amend
5. git commit -m 'second and new commit' thefile
6. no rebase, nothing
If you use magit
then step 4, 5 and 6 are a single action: Commit, instant Fixup