简体   繁体   English

如何告诉git-svn文件不是二进制文件

[英]How to tell git-svn that files are NOT binary

I am converting a large SVN-repo (~28k Commits) into Git using git-svn. 我正在使用git-svn将大型SVN存储库(约28k提交)转换为Git。 When the process was through (~ 1 1/2 weeks) I encountered some .ps1-files being treated as binary in the diffs. 当该过程完成时(〜1 1/2周),我遇到了一些.ps1-文件,它们在diff中被视为二进制文件。 I have commited a .gitignore file on master (after the conversion of course) that tells git to treat the files as text: 我已经在master上提交了一个.gitignore文件(当然是在转换之后),该文件告诉git将文件视为文本:

* -text
*.snk binary
*.ico binary
*.chm binary
and so on...

Note: -text just tells it to treat line endings as is (not storing them with Unix line endings in its database) 注意:-text只是告诉它按原样对待行尾(不将其与Unix行尾一起存储在其数据库中)

However I was only able to add the .gitattributes AFTER the conversion of course. 但是,我当然只能在转换后添加.gitattributes。

The .gitattributes does not quite work out in Git-extensions for previous commits/diffs but that might be another problem that I don't want to discuss right now. .gitattributes在以前的提交/差异的Git扩展中不太适用,但这可能是我现在不想讨论的另一个问题。 The main problem is the files that are stored binary in git. 主要问题是在git中二进制存储的文件。

I read somewhere that you could store a gitattributes under .git/INFO. 我读过某个地方,您可以在.git / INFO下存储一个gitattributes。 I could do this before the conversion process but I haven't given that another try since the conversion takes more than a week and I would like to get it right at the first strike. 我可以在转换过程之前执行此操作,但是由于转换需要花费一个多星期的时间,因此我没有再尝试过,我希望在第一次执行时就正确解决。

So basically my question is now the following: With the converted repository in mind: Can I convert existing binary files in an existing git repository to text files? 因此,基本上我的问题现在是:考虑转换后的存储库:我可以将现有git存储库中的现有二进制文件转换为文本文件吗?

If not: How would I tell git-svn which files are to be treated as text/binary using gitattributes for the whole conversion procedure? 如果不是:我如何在整个转换过程中使用gitattributes告诉git-svn将哪些文件视为文本/二进制文件?

EDIT: The problem was not anything in the conversion (git treating files as binary on purpose) but files being treated as binary by 'git diff' or Git-extensions. 编辑:问题不是转换中的任何内容(git故意将文件视为二进制),而是通过'git diff'或Git扩展名将文件视为二进制。 (see answer) When using a diff tool (for example BeyondCompare) you can still work with those files. (请参阅答案)使用差异工具(例如BeyondCompare)时,您仍然可以使用这些文件。 It is then only a little annoying in the history. 这在历史上只是一点点烦人。 The conversion worked flawless since the files were migratet as is. 由于文件是按原样迁移的,因此转换工作正常。 (UTF-16 that is) (即UTF-16)

The binary attribute "macro" is a shorthand for -diff -merge -text (see gitattributes docs ). binary属性“ macro”是-diff -merge -text的简写(请参阅gitattributes docs )。

In opposite to the the text -attribute which influences the line ending conversion of files between the repository and the working copy version, the diff and merge -attributes do not influence how Git stores files. 与影响存储库和工作副本版本之间文件行尾转换的text属性相反, diffmerge属性不影响Git存储文件的方式。 The latter two attributes just influence how Git interprets file contents (eg how Git creates a diff/patch for a file). 后两个属性仅影响Git 解释文件内容的方式(例如,Git如何为文件创建差异/补丁)。

If you have no explicit .ps1 binary , or .ps1 -diff in your .gitattributes , the reason why git diff interprets your .ps1 files as binaries is probably because of their encoding. 如果你没有明确.ps1 binary ,或者.ps1 -diff.gitattributes ,为什么原因git diff解释您.ps1文件,二进制文件,可能是因为他们的编码。 Note that Git doesn't support UTF-16/UCS-2, for example. 请注意,例如,Git不支持UTF-16 / UCS-2。

If this is the case, you can either create a custom "diff driver" which converts the files to UTF-8 (like proposed in this answer ). 在这种情况下,您可以创建一个自定义的“差异驱动程序”,将文件转换为UTF-8(如本答案中所建议)。

Or, as the Windows PowerShell can also cope with UTF-8 script files, you could convert all your .ps1 files to UTF-8. 或者,由于Windows PowerShell也可以处理UTF-8脚本文件,因此您可以将所有.ps1文件转换为UTF-8。 (If you want to convert files in existing/migrated commits, you could use git-filter-branch .) (如果要转换现有/迁移的提交中的文件,则可以使用git-filter-branch 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM