0

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?

4
  • If this is a build product, why is it checked into your repository? Build products shouldn't generally be checked in. Commented Feb 26, 2022 at 18:46
  • It's a bit more complicated. This can't be changed. Commented Feb 26, 2022 at 19:23
  • 1
    Well, if you talk to the Git developers (of which I am one), the answer is, "Don't do that." So you should edit your question to provide the relevant context explaining what your goal is checking it into the repository and why it can't be changed if you want an answer that's going to help you accomplish your goal. Commented Feb 26, 2022 at 19:28
  • I still don't think it is relevant here, but in general, the project is written in Python. In some cases it just runs, in others, it gets built by an internal build system. This file's presence is required for it to run without building. And changes in it made by the build process shouldn't be checked into the repository. Commented Feb 27, 2022 at 10:03

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.