3

The scenario:

  • dev in the master branch
  • fork master into a Feature branch, and send it to QA, with one Feature in it
  • dev some more in master
  • git checkout Feature
  • make one little fix
  • send Feature, with that fix, back to QA
  • git checkout master
  • git merge Feature

Imagine my surprise when Git said "okay, you want master to look like Fix now", and threw away all of my "dev some more" changes. I need it to only apply the only hashtag that differed from when the two branches forked.

How do I perform this simple & obvious scenario? The nightmare would be me making the same change in master, then getting an irrelevant irreconcilable merge conflict when the same change goes into a "production" branch...

Phlip
  • 5,253
  • 5
  • 32
  • 48

2 Answers2

5

If nobody depends on your feature branch (ie if nobody has pulled from hat branch that you have pushed), I would, to be sure, rebase it on top of master:

git checkout master
# make sure master is up-todate
git pull

# rebase my feature branch on top of master
git checkout myFeatureBranch
git rebase origin/master

That replays your modifications on top of master, and you can resolve any conflict locally within your feature branch.

Then the merge back to master is a trivial fast-forward one

git checkout master
git merge myFeatureBranch

Finally you can push master: the upstream repo will accept those changes again as a fast-forward merge (you are only adding new commits on top of origin/master)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Unfortunately for our thread, git cherry-pick worked. In this case, there was only one hashtag to pick. I suppose I could have cherry-picked a list of them. But I also thought (from twitter) that rebase was evil, so this answer must go unconfirmed. Tx all! – Phlip Jan 08 '14 at 17:12
  • 1
    @Phlip I don't trust cherry-picking unless it is a one-time operation (meaning you will leave that branch from which you are cherry-picking behind and not use it anymore). See http://stackoverflow.com/a/18445186/6309 – VonC Jan 09 '14 at 06:22
2

You have 2 possibility : 1/ You should first merge your master changes on your Feature, resolve your conflict potentially, then when it's ok, merge your Feature in the master.

git checkout master
git pull
git checkout Feature 
git pull 
git merge master --no-commit --no-ff

# Analyze the changes that will be merged into your Feature
git commit 
git push

and do the same merge on your master

2/ Cherry pick the commits you want, update conflict and commit.

git cherry-pick _your_Hash_
Franck
  • 1,354
  • 12
  • 17
  • Your first suggestion looks like I want to put all of the HEAD of master into Feature; I want to leave Feature alone. I will try your second suggestion. – Phlip Jan 08 '14 at 16:59