19

I maintain a fork of a repo.

That repo which has been tracking a binary file (which is a sqlite3 file).

Every time I pull from that repo, I experience merge conflict due to that binary file.
What is the right way to solve this kind of merge conflict?

What is the right way to manage binary files (like this sqlite3 *.db file) in git?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
shadyabhi
  • 16,675
  • 26
  • 80
  • 131

2 Answers2

11

You could define a custom merge driver specifying to always "keep theirs" (copy the version you are pulling) on top of your current version.

.gitattributes

mysqlite3.db merge=keepTheir

(That being said, remember binaries aren't always best managed with Git, especially if they are modified often)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I cant find .gitattributes. Do I have to create a file in $GIT_DIR/info/attributes? – shadyabhi Mar 25 '11 at 16:24
  • @shadyabhi: No, you have to create a file called `.gitattributes` in the parent directory of the things you want it to apply to (probably the top level of your projects), just like with a `.gitignore`. The `$GIT_DIR/info/attributes` would only apply to your specific clone of the repo, not others, since it's obviously untracked. – Cascabel Mar 25 '11 at 16:30
  • @shadyabhi: The question http://stackoverflow.com/questions/1910444/git-merge-s-theirs-needed-but-i-know-it-doesnt-exist/1910479#1910479 gives you a more detailed example. – VonC Mar 25 '11 at 16:32
  • 1
    @Jefromi Do files like .gitignore & .gitattributes are added using "$git add"? Also, I am new to all this, can you please guide to a nice documentation. Most tutorials I saw didnt give nice examples of merging and solving conflicts. – shadyabhi Mar 25 '11 at 16:39
  • @shadyabhi: Yes, that's the point; you track them in your repository so that all clones of the repository ignore the same things (e.g. build objects) and use the same attributes (e.g. that file is definitely text, merge this file that way). For documentation, I will always recommend the man pages. In this case, [`man gitattributes`](http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html). – Cascabel Mar 25 '11 at 16:42
  • @shadyabhi: As for resolving conflicts, this is kind of a special case, but for the more normal kinds of merge conflicts (in actual code/text), there's great information in the [`git-merge`](http://www.kernel.org/pub/software/scm/git/docs/git-merge.html) manpage. – Cascabel Mar 25 '11 at 16:49
3

I've released a tool that does what you're asking for. It uses a custom diff driver leveraging the sqlite projects tool 'sqldiff', UUIDs as primary keys, and leaves off the sqlite rowid. It is still in alpha so feedback is appreciated.

https://github.com/cannadayr/git-sqlite

cannadayr
  • 393
  • 3
  • 7