Home > OS >  How to setup git in a local workspace to accept all incoming changes by default for some files?
How to setup git in a local workspace to accept all incoming changes by default for some files?

Time:08-08

I have a folder that is set to be compiled whenever I do some changes. Sometimes, however, I do some changes that are not supposed to be compiled, such as testing something.

The compiled files contain the current date of compilation, so even if the two compiled files are the same the time would be different in both. Now this is not a problem until I have to merge some changes.

How do I set up my configuration so that a specific folder (in my case compiled) is always Accept Theirs by default without asking me to git pull -X theirs compiled every single time?

Or if you have any alternative method of doing the same thing differently? The reason for this is because whenever I merge and the other person has compiled on his machine and pushed the compiled code, I will be receiving the compiled code of his which result in a merge conflict.

The compilation locally doesn't matter as it's just a bunch of compiled stuff for production, but for the online repo, or for someone who's cloning the repo just to try it out the compiled files should be present, therefore I cannot add the folder to .gitignore as that will prevent it from coming up entirely.

Edit:

I tried GitHub actions to do the compilation on the repo itself, which does work, but still gives me the same problem of having to merge when I receive the new pull, or the compiled files are stored in releases/artifact repo so I no longer have them locally.

CodePudding user response:

but for the online repo, or for someone who's cloning the repo just to try it out the compiled files should be present, therefore I cannot add the folder to .gitignore as that will prevent it from coming up entirely

That's exactly how it's supposed to work. You don't commit compiled code for that reason. Another person checking out your repo will have to compile it locally, and you will have to compile it somewhere else before you deploy it to a server.

Git is for source code, not for artifacts.

As far as I know, you can't do what you want (have a directory with ever changing files committed, but unconditionally taking theirs in case of conflicts). It's a workflow problem, not a Git problem.

Can't you like have those compiled files be in a package (npm/composer/NuGet/zip/...) and have them be pulled on build or using a script? Then release a new version when they actually changed.

  • Related