Every time we make changes to the .strings files (for iOS localization) from different branches, we will have conflicts.
The reason seems to be that git consider the .strings as binary files instead of text files. Sometimes it is a little annoying because git won't help merging the changes automatically, again, because they are considered as in binary format.
Is there any git settings that will force it to consider a file as text file.
I notice that both SourceTree and GitLab won't be able to tell that it is text file. But XCode itself will be able to show us the diff. Not sure this is related or not.
Any binary format can be diffed with git, as long as there's a tool which converts the binary format to plain text. One just needs to add the conversion handlers and attributes in the same way.
While both binary and text files contain data stored as a series of bits (binary values of 1s and 0s), the bits in text files represent characters, while the bits in binary files represent custom data. While text files contain only textual data, binary files may contain both textual and custom binary data.
Git can usually detect binary files automatically. No, Git will attempt to store delta-based changesets if it's less expensive to (not always the case). Submodules are used if you want to reference other Git repositories within your project.
The only part of the GitHub web interface which allows you to push a binary (or any other file you want) is when creating a release.
Create a .gitattributes
file at the root of your repo with this contents:
*.strings diff
More information: https://git-scm.com/docs/gitattributes
None of the solutions worked for me, so I did some more research and at this link I found out this:
in your project main directory, create or edit a .gitattributes file adding this line:
*.strings diff=localizablestrings
in the .gitconfig file in your home directory, add these lines:
[diff "localizablestrings"]
textconv = "iconv -f utf-16 -t utf-8"
This did the trick.
After trying Jonathan or Slawomir's solution, I am still not able to see the diff properly. They are still being considered as binary file.
I finally figure out that the our localizable.strings file are not in UTF-8 encoding but in UTF-16 encoding. After changing the encoding back to UTF-8, it works fine.
Is it okay to change the encoding? Yes, it is. It is actually recommended by Apple to use UTF-8.
Note: It is recommended that you save strings files using the UTF-8 encoding, which is the default encoding for standard strings files. Xcode automatically transcodes strings files from UTF-8 to UTF-16 when they’re copied into the product.
[reference]
How do you know what encoding that file is? See this for command line and this for Xcode:
file -I vol34.tex
See comments below, you may have to change the encoding of the file manually:
iconv -f UTF-16 -t UTF8 file.strings
Please add in your project root directory file .gitattributes
with content:
*.strings text
Now git will recognize your files .strings
as text files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With