2

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

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.

Full Time Skeleton
  • 1,680
  • 1
  • 22
  • 39

1 Answers1

2

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

git clean -fd -- path/to/folder

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

And you're done! Now just git add -A -- path/to/folder to stage the folder.

ChrisB
  • 1,540
  • 6
  • 20
  • Thanks - if I do the following should I be ok? I run a git log (I just did this in the merge and it listed all recently commits on my branch (not master, which is fine). I can see a commit that I recently did on my branch which will presumably have my branch's version of the folders in question. Do I simply put the hash (the guid-like character string that appears after the 'commit' heading in each log result) of the commit I want and then -- path/to/folder? – Full Time Skeleton Mar 30 '23 at 10:21
  • @FullTimeSkeleton: yes – ChrisB Mar 30 '23 at 10:22
  • I put my trust in you sir.....here we go.... – Full Time Skeleton Mar 30 '23 at 10:23
  • If you are new to git and you have lots of unsynchronized local work, backup your local repository folder before doing stuff like this. – ChrisB Mar 30 '23 at 10:24
  • Currently running it....takes a while cause these folders are massive. – Full Time Skeleton Mar 30 '23 at 10:28
  • Update - It's finished now. When looking in Visual studio's git merge window the folders are still appearing as unmerged changes though. One of the smaller folders disappeared, maybe it takes a while to update given the sizes of these folders. – Full Time Skeleton Mar 30 '23 at 10:34
  • Let's continue this in [chat](https://chat.stackoverflow.com/rooms/252874/room-for-chrisb-and-full-time-skeleton) to avoid the spam here :). – ChrisB Mar 30 '23 at 10:37