This question is related to the following questions: https://stackoverflow.com/search?q=[git]+%2Bassume-unchanged, however, none of the provided answers to these questions seem to meet my needs.
I have a header file (key_info.h) that gets generated by a python script. To be clever, I version controlled a placeholder version of the header (key_info.h) with a single line of code:
int i = you_need_to_run_the_key_info_gen_python_script_to_generate_this_file();
Prior to running the python script, compiling this code will yield an error telling the developer exactly what to do; run the script.
Naturally, the developer will proceed by running the python script to generate the latest version of key_info.h and the code will successfully compile. The developer will then go on to make a series of changes and then 'git commit' their code.
The problem we run into is the fact that key_info.h has now been modified. As such, git will pick it up as a modification and will allow it to be committed. However, the generated version of this header should never be version controlled. We need the placeholder version to remain unchanged to continue to provide the compile error hint to developers.
My first instinct was to use .gitignore to prevent git from picking up key_info.h in a commit. .gitignore is then easily shared between developers since .gitignore itself is version controlled. Unfortunately, .gitignore only works for files that aren't version controlled.
My next thought was to use 'git update-index --assume-unchanged /path/to/file'. This works great locally, but I have no way of enforcing this rule upon other developers. It's only a matter of time before a dev accidentally commits the generated header.
So my question is this: is there a way to version control a file, while silently enforcing a rule that the file is to be ignored when it comes time to commit changes? What I really want is .gitignore for version controlled files.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…