How to prevent merging of excluded files?
Let's say I have file secret_config
in .git/info/exclude
. My colleague, who doesn't know about this file, thinks file with such name might look shiny in his repos开发者_开发百科itory, so he creates, commits and pushes it. I, in good mood, want to pull
, as every morning, but git starts to yell at me:
error: Untracked working tree file 'secret_config' would be overwritten by merge. Aborting
How to tell git to stop yelling at me? Is it possible to tell him to completely ignore this file even while pulling or fetching/merging?
Edit:
When I temporarily create .gitignore
and put secret_config
to it, it, at least, allows me to pull properly. I need to emulate this functionality somehow.
You can share your list of ignored files via .gitignore
, e.g.
$ mv .git/info/exclude .gitignore
$ git add .gitignore
$ git commit -v "Add ignored file list"
$ git push
Next time he pulls he will inherit your list of ignored files. This doesn't fix the history of files he already committed in his repository though.
It's not exactly a solution, but there's possibility to change merging strategy, so file always keeps your local version. You just need to create file .gitattributes
in the same directory as file you want to prevent merging and put name_of_file merge=ours
in it. Downside is, you have to commit this file, so it feels like polluting repository with junk that no one but you needs.
精彩评论