Home > Net >  Ignore merge conflicts for a specific file
Ignore merge conflicts for a specific file

Time:02-28

I have a file that is in a repository and added to .gitignore. When I build the project, this file gets modified, but changes are purposely local and shouldn't end up in the repo. The file presence is also required in the repo so I can't remove it.

The problem is that whenever I do git pull I get conflict, due to a fact that the file has been changed locally, and I need to remove this file for pull to finish successfully. Is it possible to ignore merge conflicts in this file and always replace it with a version from the repository?

CodePudding user response:

I think you can use git pull -X theirs to resolve conflicts using the repo version of the file.

CodePudding user response:

Git doesn't provide a way to do what you want. Git provides options which explicitly perform a merge without changing anything at all (-X theirs) and options which use a custom merge driver to perform a merge, but neither of those is going to do what you want in this case.

Git is not intended to be used to store any sort of build artifact, so the Git developers typically aren't interested in this as a use case, and previous posts to the list on this topic have said as much. Your best bet is to store a pre-built artifact on a server and download and use that after checking a strong cryptographic hash (e.g., SHA-256). In the Perl community, building a self-contained single script with all assets and dependencies is called "fatpacking", and a similar approach may be useful for you here as well.

  • Related