Created
November 9, 2012 10:41
-
-
Save BenConstable/4045094 to your computer and use it in GitHub Desktop.
Move commits onto feature branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# If, for example, you've accidentally made some commits to master | |
# that should be on a feature branch, this set of commands will | |
# move those commits over to a feature branch and reset master to | |
# where it should be both locally and on the remote. | |
# | |
# References: | |
# | |
# - http://stackoverflow.com/questions/1628563/move-recent-commit-to-a-new-branch | |
# - http://stackoverflow.com/questions/1377845/git-reset-hard-and-a-remote-repository | |
# | |
git branch feature | |
git reset --hard HEAD~3 # 3 should be replaced with the number of commits to move | |
git push --force origin # Force update of remote master (if it's been pushed) | |
git checkout feature | |
# | |
# As a function: | |
# | |
# `move_feature numCommits branchName` | |
# | |
function move_feature () { | |
git branch ${2} && git reset --hard HEAD~${1} && git push --force origin && git checkout ${2} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment