简体   繁体   English

git diff在shell脚本上

[英]git diff on shell scripts

I want to add shell scripts (".sh") into a git repository. 我想将外壳脚本(“ .sh”)添加到git存储库中。 But when viewing them in the git web interface it recognises them as binary files. 但是,当在git Web界面中查看它们时,它将它们识别为二进制文件。 Therefore I can not view them online or see diffs between different commits. 因此,我无法在线查看它们,也看不到不同提交之间的差异。

Is there a way to tell git how to handle these shell scripts? 有没有办法告诉git如何处理这些shell脚本?

You can tell git that these files are text files using the .gitattributes file . 您可以使用.gitattributes文件告诉git这些文件是文本文件 The simplest way is to say that all .sh files are text. 最简单的方法是说所有.sh文件都是文本。 Put this in a .gitattributes file in your repository root: 将其放在存储库根目录下的.gitattributes文件中:

*.sh    text

This might not fix your issue, though. 不过,这可能无法解决您的问题。 When you say 'git web interface', do you mean 'Github'? 当您说“ git web interface”时,您是指“ Github”吗? I couldn't find any documentation about whether Github uses the .gitattributes file when determining the file type. 在确定文件类型时,我找不到有关Github是否使用.gitattributes文件的任何文档。 But this will let you run git diff on your local repository, at least. 但这至少可以让您在本地存储库上运行git diff

There's some more documentation about .gitattributes in the Pro Git book . Pro Git书中还有更多有关.gitattributes文档。 That approaches things in the other way, though: making binary files available as text, for meaningful diffs. 但是,这以另一种方式处理事情:使二进制文件作为文本可用,以实现有意义的差异。

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

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