问题描述:

I have ran into this situation a few times and I am curious how others handle this.

Let's say I have two branches on the remote server that look like this:

branchA: a123-->b123-->c123-->e123-->f123

branchB: a123-->d123-->b123-->c123

Let's assume that d123 was committed before b123 and c123 on branchB. At some point, we need to rebase branchA onto branchB because it has work that branchB needs. A colleague does that, cleans up the conflicts, all is well and branchB is pushed back up to the remote server. My local branch now is clean and looks something like branchB used to look:

local branchB: a123-->d123-->b123-->c123

Naturally, I need to rebase what's in the remote server from branchB onto my local branchB so I have the work. Sometimes though, I run into a situation where I have conflicts in my local branch and git asks me to go through each of them, as rebasing usually works. This is because I don't actually have the history from branchA that was rebased into branchB by a colleague.

The problem is that I know all of the work I have done up until this point is in the remote branchB and there are no conflicts to actually fix. Going through each of them would be a waste of time. I just want the history that's on the remote branchB to replace my local history.

Scouring the Internet there seems to be a few different solutions to the issue but I am not quite sure which one is best or Linus approved if you will. I actually am not sure if I have even found the answer I am looking for.

Some answers say that I should be using a rebase and using the theirs option or picking a different strategy. I believe some answers say that the --skip is appropriate here... However it looks like git --skip literally skips commits in some cases. Also, it looks like using the theirs option like git rebase -X theirs actually rewrites the SHAs for me in some cases which throws the history out of whack, which is not what I want.

So, my question is how would I reconcile the history on my local branch with the history on the remote branch when:

  • Everything in my local branch is already in the remote branch?
  • My branch is clean, has no pending changes and there really aren't any conflicts to fix?
  • Really all I want is to replace what's in my local branch history with what's in the remote branch history?

网友答案:

Really all I want is to replace what's in my local branch history with what's in the remote branch history

Just do a hard reset:

git checkout branchB
git fetch
git reset --hard origin/branchB
相关阅读:
Top