You develop a new feature on the branch new-feature. You have already
implemented the first part of a feature, when you are notified of a critical
bug that has to be fixed right away on the master branch.
After the bug fix, you continue to work on the new feature. After you committed
the second part of the feature, you realize that you have done your commit on
the master branch instead of the feature branch.
- Run
source setup.sh(or.\setup.ps1in PowerShell)
- Move the faulty commit from the
masterbranch to thenew-featurebranch. - How would you also bring the bugfix to your feature branch?
git reset HEAD~1to move the current branch one step back. This has the consequence of removing the newest commit from a branchgit stashto temporarily save your changes so that you can switch branchesgit cherry-pickto add changeset from commit on current branch