Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Created June 29, 2017 17:54
Show Gist options
  • Save drmmr763/478a70bd44766159f974d74a6edd42cc to your computer and use it in GitHub Desktop.
Save drmmr763/478a70bd44766159f974d74a6edd42cc to your computer and use it in GitHub Desktop.
fix commits when you commit on the wrong branch
git checkout -b 'feature-a'
 - git commit -m 'working on feature a'
 - git commit -m 'working on feature a'
---
 - git commit -m 'working on feature b'
 - git commit -m 'working on feature b'
 - git commit -m 'working on feature b'
---

git checkout master
---
crap just realized I commited on the wrong branch!

# get my commits on the right branch:

git checkout -b 'feature-b'
git cherry-pick sha1 for feature-b commit
git cherry-pick sha2 for feature-b commit
git cherry-pick sha3 for feature-b commit

# remove my commits from the wrong branch:
git checkout 'feature-a'
git revert sha1 for feature-b commit
git revert sha2 for feature-b commit
git revert sha3 for feature-b commit

git push upstream feature-a
git push upstream feature-b 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment