I'm in the process of editing my source files to produce a new commit atop my dev
branch. My changes are saved on disk but not yet staged.
Then I notice a small mistake introduced by a former commit, say HEAD~10
. Once fixed, the result is only one (or a few) additional git diff hunk(s) on my disk.
I don't want these hunks to be recorded within the new commit, because they belong to HEAD~10
. So I need to rebase. Here is my workflow then, but I'm not satisfied with it:
$ git stash # save my current work + the small fix
$ git rebase --interactive HEAD~11
# set first commit appearing in todo list to `edit` action
$ git stash pop # re-introduce my changes here (**may conflict**)
$ git add --patch fixed_files # or similar, to only stage relevant fix hunk(s)
$ git commit --amend # fix old commit
$ git stash # save my current work again
$ git rebase --continue # get back to my current commit (will likely *not* conflict)
$ git stash pop # back here with HEAD~10 fixed
What I'm not happy with is that the process is complicated, and that the first git stash pop
line may introduce meaningless conflicts, even though I'm confident that no conflicts will occur during execution of the git rebase --continue
line.
Is there a better way? Suppose I only have a few staged hunks in HEAD
, can I easily introduce them earlier in my branch with some magical:
git amend-old-commit-then-rebase HEAD~10
yet keep my unstaged changes? (of course I'd be warned in case the inherent rebase does conflict)