Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Git, is there a way to mark a file as "pure"? [duplicate]

Tags:

git

Possible Duplicate:
Locking binary files using git version control system

I am committing a file which should never be merged, but overwritten (perhaps with a warning) when other people pull. Is there a way of accomplishing this?

like image 834
Christian Neverdal Avatar asked Feb 11 '12 23:02

Christian Neverdal


1 Answers

It's a little unclear what your actual situation is. The first question you should ask yourself is whether the file actually needs to be tracked - unmergeable files are often derived files, as you suggest in the comments, and therefore don't need to (and shouldn't) be tracked.

If you really do need to track it, is it a binary file? Git doesn't try to merge binary files - they always show up as merge conflicts. Git is good about detecting binary files, so in this case, you're probably safe. If it's not a binary file, then you still force Git to deal with it appropriately. In a .gitattributes file, add something like:

path/to/file merge=binary

This will direct it to treat it as a binary file for purposes of merging. You could also, if you wanted, define a custom merge driver. Use merge=my_merge_driver in the gitattributes file, then in your gitconfig add something like:

[merge "my_merge_driver"]
    name = descriptive name
    driver = my_script %O %A %B

The three arguments for the script are the common ancestor version (O for original), the current branch's version (A) and the other branch's version (%B) - they're temporary files, and the merge driver is supposed to do the merge and leave the result in %A. See man gitattributes for more about this.

like image 119
Cascabel Avatar answered Sep 22 '22 19:09

Cascabel