views:

410

answers:

2

I'm currently in branch 'foo'. I just ran git merge master. Only problem is there was a certain file in foo that I wanted to keep. Is there a way to get it back but keep all the other changes from merge master?

A: 

I'm not sure how to correct the problem from the current situation, but you may want to look at git merge -s ours. The docs are here.

A workflow would be

  1. Create branch a from master
  2. Do a custom change in branch a that you will not want to merge back into master
  3. Check out master and git merge -s ours a
  4. Check out a and continue working and committing.

Now when you merge with master, the custom changes in step 2 will be ignored.

Gattster
+4  A: 

Try something like this:

git checkout HEAD^1 -- filename

As far as I understand, but not being a git expert this should work.

Bartek
Or if the merge is not yet complete (due to conflicts), just git checkout filename.
ceretullis
@ceretullis: if it's due to conflicts in the file in question you will need `git checkout --ours filename`.
Charles Bailey
I actually ended up finding this elsewhere but used a commit hash instead of HEAD^1 ... thanks!
tybro0103
@"Charles Bailey" yup, left that out.
ceretullis