'Commit changes to a different branch

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?

git


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source