5

Git for Windows.

I am learning Git. My project has some projectname.hmxz file instead of the simple text files. This file is a zip-archive (with the changed extension). It is a special file of project used by Help&Manual program. Can I use Git for such projects? It disturbs me, because each branch will have modified version of the projectname.hmxz file, which is not a usual text file. How Git will merge such branches with a single projectname.hmxz file? I think the same problem will be with MS Office documents: xls, doc, etc (because it is not a plain text also).

I haven't problems with usual text files, but what about such cases?

Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
  • no, git can only merge line-based text files. even with single-line xml/html files you're out of luck. – Marian Theisen Jul 17 '15 at 14:35
  • Interesting blog post regarding diffing Word documents using `pandoc`: http://blog.martinfenner.org/2014/08/25/using-microsoft-word-with-git/ – nwinkler Jul 17 '15 at 14:36
  • For merging binary files, you are limited to choosing between files on current branch and files on other branch. See http://stackoverflow.com/questions/278081/resolving-a-git-conflict-with-binary-files – werkritter Jul 17 '15 at 14:36
  • @nwinkler, OP asks about merging files. The blogpost says explicitly that Word documents, being binary files, cannot be merged as-is — i.e., without converting them into some text format. And such conversion would be one-way in most cases, I think. – werkritter Jul 17 '15 at 14:39
  • @werkritter Yes, I know - that's why I posted the link as a comment and not as part of an answer. It's not answering the question, but it goes in a similar direction - it might give some additional background info. – nwinkler Jul 17 '15 at 14:43
  • You can use a merge tool that can handle these binary files. – poke Jul 17 '15 at 14:51

4 Answers4

5

Zip files:

No, they're binary. For binary files merge conflicts are resolved only as " use version A" or" use version B".

But if you build them from some source, maybe you can version-control that source.

MS Office files:

No, not possible. But they're often treated as text files, so at the first merge git will corrupt them. You should manually configure git to treat them as binary. Follow this instruction: https://stackoverflow.com/a/30731818/2790048

Community
  • 1
  • 1
Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
1

Git can merge only text files, however...

You can convert binary files into text files and diff them using textconv option in the configuration, but it is not trivial if you don't have a good converter.

Check this answer on superuser for detailed explanation.

Community
  • 1
  • 1
Luboš Turek
  • 6,273
  • 9
  • 40
  • 50
1

You can't do much besides choosing one version over the other.

Say you're on the branch here and want to merge it with branch there. In order to do that, you'd have to use the ours option of the recursive strategy (by the way, note that recursive is the default merge strategy):

git merge --strategy=recursive -Xours there

To do the opposite thing (favor the files from there), run:

git merge --strategy=recursive -Xtheirs there

Be wary that it affects conflicts for all files, not just binary files!

For more information see git-merge(1) manpage. I don't know the Windows equivalent, but you can also find it at the following link: https://git-scm.com/docs/git-merge

werkritter
  • 1,479
  • 10
  • 12
0

Although git can not merge binary files natively, you can configure custom merge-drivers. Thus if you have/write a program that is actually able to merge two files, you can use that to automatically merge two files. However the only non-demo driver I could find was the npm-merge-driver. If the merge-driver fails you still need to merge manually.

Additionally you can configure merge tools in git. That way you can pass the two/three versions of a file to program of your choice. Again a quick search did not show a way how to do script this using Word. However there are plenty of blog entries explaining how to do this in detail, I'm therefore only referencing the manual.

Morty
  • 2,889
  • 2
  • 19
  • 28