I've got some unpushed git commits in my child of our master branch. I did a rebase to a feature branch, and successfully merged the few conflicts that resulted, but I didn't realize that rebase wouldn't leave me on the feature branch. If I now git checkout the feature branch, it will presumably overwrite my committed changes in my working tree, leaving them in some kind of limbo. I could "git checkout -m", but that apparently is only for merging uncommitted local changes. How can I get onto the feature branch and keep my unpushed-but-committed changes that I currently have under the master branch (without pushing them to the master branch)? Should I have used git rebase -onto? If so, what should I do now that I've rebased without -onto?
preguntado el 27 de agosto de 11 a las 22:08
Puedes hacerlo así:
git checkout branchto checkout the feature branch.
git reset --hard masterto move the branch to be the same commit as
masterright now. By doing this, you lose all commits that are in the branch. Because of your rebase, all those commits should have copies on
master, so you shouldn't actually lose anything.
git checkout masterpara revisar
git reset --hard origin/masterreiniciar
masterto the state that is on the
originrepo. This assumes you didn't have any unpushed changes to
master. If you do, replace
origin/masterwith the commit id you want to reset to.
First to restate your situation to make sure I understood correctly. You made a few commits on
master and wanted to move them to
feature, so you ran
git rebase feature? First, you want to undo that. Assuming you still have
master checked out, and haven't done any rebases since, run
git reset --hard ORIG_HEAD to undo the rebase.
Now, for the proper way to move your commits over to the
feature branch. Make and checkout a temporary branch so you don't mess up
git checkout -b temp
Now rebase all the changes made since the last commit on
git rebase --onto feature origin/master
That moves the
temp branch as if it was branched from
feature. Now to merge the changes onto
git checkout feature git merge temp git branch -d temp
It will be a fast-forward merge since you just rebased.