re-commit your changes onto the new branch as a single commit. apply all the committed changes to the new branch create other-branch (if it doesn't already exist) ![]() stash the committed changes as a single temp commit onto the stack. But if you wanted to rewind n commits, then you can do git reset HEAD~n.Īlso, if you ended up committing to the wrong branch, and also ended up write some more code before realizing that you committed to the wrong branch, then you could use git stash to save your in-progress work: // save the not-ready-to-commit work you're in the middle of NOTE: in the above example, I was rewinding 1 commit with git reset HEAD~1. re-commit your changes onto other-branch add the changes you want with git add. This also deletes the temporary commit from the stack of temp commits. take the temporary commit you created, and apply all of those changes to the new branch. checkout the other branch you should have committed to. create other-branch (if the other branch doesn't already exist) all temporary commits created with git stash are put into a stack of temporary commits. temporarily save your unstaged changes as a commit that's not attached to any branch using git stash this takes all changes in your most recent commit, and turns them into unstaged changes. If you just committed to the wrong branch, and have not changed anything since, and have not pushed to the repo, then you can do the following: // rewind master to point to the commit just before your most recent commit. ![]() I recently did the same thing, where I accidentally committed a change to master, when I should have committed to other-branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |