5 ms·
> Oh shit, I accidentally committed to the wrong branch! Other ways to do it (that don't require to retype the commit message): - rebase onto the correct branc
by glandium 10y ago
> Oh shit, I accidentally committed to the wrong branch!
Other ways to do it (that don't require to retype the commit message):
- rebase onto the correct branch:
git branch foo
git reset --hard HEAD~
git rebase --onto name-of-the-correct-branch HEAD foo
git checkout name-of-the-correct-branch
git merge foo
git branch -D foo
- cherry-pick
git reset --hard HEAD~
git checkout name-of-the-correct-branch
git cherry-pick name-of-the-branch-you-mistakenly-committed-to@{1} (or git cherry-pick HEAD@{2})
> Oh shit, I tried to run a diff but nothing happened?!
You probably want to know `git diff HEAD` too.
Edit: formatting.