How to handle tracked generated files in git?

Background:

We created files in our system that should be committed in the final state (for example, we cannot rely on the source (non-generated) files and do the ones generated on the fly). Since we need the generated files, these files cannot be git ignored.

Problem:

Files cause a lot of errors Your local changes to the following files would be overwritten by merge from git when checking and pulling commands.

When I pull or check, I don't care what my files are, I only care about new files. (Obviously, I really care about the source file that creates the generated files. I'm glad for the merge warnings in the source file, which is stored in a different directory.)

However, when I commit, I want my version to โ€œwinโ€ and my generated files to be committed.

Possible Solution:

Now I just run git checkout -- generated-files/ before outputting or checking for reset my generated files and skip any merge errors. It works, but I often forget to do it, and I would like to automate it if possible.

I looked at the preliminary check and tightened the hook, but git does not provide them :(

Questions:

  • Is there a better way to handle generated files?
  • Is there a way to get git checkout -- generated-files/ to work before pulling or checking?
  • How do you work with generated files in git?
+6
source share
1 answer

My personal mantra: if a file can be generated, only the parts that can generate it belong to the control source. Otherwise, you will encounter a lot of noise that you are encountering right now.

If the generated files are genuine, repeating, repeatable steps and part of your build chain, it is safe to add the directory in which they live in your .gitignore file (and don't forget the git rm --cached folder so they are no longer being tracked).

If the generated files are part of the actual source code, then there should be a conversation between team members and / or facilitators and discuss why these files are under review if their generation is automated. Perhaps there are legitimate reasons to monitor them, and maybe not so - itโ€™s worth at least asking.

My recommendation is to ignore any files that were generated and leave them outside of Git. But, you will want to talk with your teammates to see if they agree with this agreement.

+3
source

All Articles