Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mid merge with git, want to ignore merge conflicts in specific folders

I’m mid way through a pretty time consuming merge (merging master into my branch) and resolved all the conflicts I need to resolve. However, git is telling me that there are a bunch of conflicts in folders that need to be resolved also.

I want to tell git to just take my branch’s version of everything in those folders and ignore anything from master. I’ve tried:

git checkout –ours path/to/folder

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But git rather unhelpfully tells me X files ‘does not have our version’

I don’t understand this because I had thought the command I was typing was telling git ‘I don’t care what the conflicts are – just take my branch’s folder and move on’. So how could it ‘not have our version’?

This seems like it should be pretty basic because the file-based equivalent is simple (merge, take our branch version, take master branch version). I would have hoped an equivalent existed for a folder (i.e. take our branch version of everything in this folder)

I’m very conscious of messing this up and so while this question on SO appears to be asking pretty much the same thing, the answer seems to involve multiple steps and I’m wary of screwing up the whole merge and having to start again.

Suggestions as to how I can accomplish this kind of ‘ignore all conflicts in this folder’ are welcome.

>Solution :

A simple solution would be:

git checkout <COMMIT_HASH> -- path/to/folder

If git log does not give you a usable commit hash because of the merge,
you can get a recent one from git reflog.

If you have new files that were not indexed at that time,
you can delete them using

cd path/to/folder
git clean -fdx

!!! In order to not mess up here and remove stuff you still need, dry-run that command
ahead of time using git clean -ndx

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading