Say I am working in a branch called "feature/nice-task"
. I am asked to urgently drop whatever I am working on and fix a huge critical bug that my ex-coworker John Doe left right before being fired for poor coding practices.
I create a branch "bugfix/horrible-bug"
, but in a wave of anger forget to switch to that branch. So, I continue to work in "feature/nice-task"
, and spot it right before I am going to commit. Is there still a way for me to commit these changes to "bugfix/horrible-bug"
without spoiling "feature/nice-task"
with unrelated commits?
What do I do?
CodePudding user response:
- Branch from where you are to create a temporary backup of all work.
- Commit any uncommitted work to the temporary branch.
- Checkout the commit from which you want to create the branch you intended to create.
- Create the branch you intended to create.
- Cherry-pick the commit(s) you need from the faulty branch.
- Reset the faulty branch to the last good commit.
- Delete the temporary branch.
All these steps are covered well in other tutorials and discussions, so I won't provide specific commands.