tags:

views:

52

answers:

2

I'm working in a multi-user git environment. My workflow is to work in a branch, and pull from the remote into local master, then rebase my working branch, merge the branch with local master, then push to the remote repo.

In the most recent pull there 6 new commits, one of them my code needs to take precedence over.

If I rebase, I'll need to resolve several conflicts, and then replace existing objects with my own. I can do that, but it seems pretty manual, and begging for problems.

What's a better way to handle this?

A: 

I'm not sure there is a better way. If two commits conflict then you have to tell git how to resolve it.

Your question suggests that it's a little bigger than that, though. It sounds like you've done "framework A with supporting object B" and the mainline has done "framework C with supporting object D" and you want to discard C&D in favour of A&B. Is that correct?

If so, then you're still stuck with the same problem: you need to decide what to tell git. If new code has supplanted old code then git can't know unless you tell it.

Ultimately, you'll have to either rebase or merge and both will have the same set of conflicts.

Cameron Skinner
Yes, that pretty much sums it, I was hoping I could pull up to the offending commit, merge my changes, then pull the rest, rather than the door to door fighting I'm looking at.
Joe Cairns
You can (kinda) do that...you can pull commits one-by-one and fix them as you go rather than doing a big pull-and-merge. Rebase will effectively do that, but it will merge *your* commits one-by-one rather than the mainline ones.
Cameron Skinner
After reading the other answer I see I misunderstood slightly: it wasn't clear that you wanted to *completely* discard a mainline commit. In that case `revert` is the way to go.
Cameron Skinner
+2  A: 

You can git revert the bad commit in the master branch, and then rebase to your topic branch:

git checkout master
git revert <sha1>
git rebase master topic
Gabe Moothart
Small nitpick: You can shorten the last two `git` commands into `git rebase master topic`.
Frerich Raabe
@Frerich fixed, thanks!
Gabe Moothart
Thanks Gabe and French, I think this is exactly what I was looking for but couldn't get my head around for some reason. Seems perfectly clear and exactly what I was trying to do.
Joe Cairns