Re: How to fix “Your branch and 'origin/master' have diverged” after editing a commit that came before a pull?
- From
- Gavin Guo <tuffkidtt@gmail.com>
- Date
- Nov 21, 2010, 14:45 UTC
- Message-ID
- <AANLkTikCnX5aBrmh9+wnb9JyOiynv0zhrpdMJwbhL2ji@mail.gmail.com>
- In-Reply-To
- <20101120043628.GB20725@sigill.intra.peff.net>
Show 6 quoted lines
> To fix it, what you want to do is recreate the history on top of B' as > it happened on top of B. So first you go back to C', the last commit > just before the commits from upstream that were rewritten. (you will > have pick its sha1 out of the log): > > git checkout -b temp B'
I think you mean git checkout -b temp C'
Show 34 quoted lines
> You should then have: > > A--B'--C' > > on a temporary branch. Now re-pull from upstream (you could also > manually rebase those commits, but this is probably simpler, especially > if there actually was a merge): > > git pull remote_name branch_name > > Note that you need to explicitly mention where you pulled from, since > the temp branch will not be configured to pull in the same way (if you > don't have any special config set up, it should be "git pull origin > master"). > > And now you have: > > A--B'--C'--D--E > > at which point we can rebase the last bit of your branch on top: > > git rebase --onto temp F'^ branch_name > > where "branch_name" is the name of the branch where this mess happened > (presumably "master"), and F' is the first commit that is worth saving > after you pulled from upstream. And that gives you: > > A--B'--C'--D--E--F''--G''--H'' > > where F'' corresponds to the original F, but actually has a different > commit id (because of different parentage) than F or F'. > > At that point your original branch should be in the state you want. You > can delete the temp branch with "git branch -D temp".
I'm sorry that I can't understand "your original branch should be in the state you want" ? You only create a temp branch, and rebase some commits on it, right ?? What does that related to original branch ??
> So that's the most general way to do it. It's a little convoluted > because of the way rebase works (you can't say "rebase those commits on > top of me", but rather have to say "rebase me on top of these commits", > which leads us to use the temporary branch).
Gavin Guo