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?
views:
410answers:
2
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
- Create branch
a
frommaster
- Do a custom change in branch
a
that you will not want to merge back intomaster
- Check out
master
andgit merge -s ours a
- Check out
a
and continue working and committing.
Now when you merge with master, the custom changes in step 2 will be ignored.
Gattster
2010-01-19 19:48:03
+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
2010-01-19 19:52:22
Or if the merge is not yet complete (due to conflicts), just git checkout filename.
ceretullis
2010-01-19 19:55:10
@ceretullis: if it's due to conflicts in the file in question you will need `git checkout --ours filename`.
Charles Bailey
2010-01-19 19:56:52
I actually ended up finding this elsewhere but used a commit hash instead of HEAD^1 ... thanks!
tybro0103
2010-01-19 20:07:20
@"Charles Bailey" yup, left that out.
ceretullis
2010-01-19 21:10:31