Today I created a commit in git, which contained changes related to two different issues. If I realised that just after the commit, I can use
git reset HEAD~
to reset the commit history to the previous state, and redo it.
Unfortunately, I found that after a few other commits.
Of course I can still reset to the earliest commit and cherry-pick all later commits, but the idea dawned on me: Can I do that with git rebase?
It turned out I can. It’s quite simple:
- git rebase -i <commit hash>
- copy and paste the commit I want to split and make both lines “edit”
- edit by disgarding unrelated changes and commit
- repeat, but for the other part
After the successful try, it seemed intuitive, and I’m glad to learn something. :)