显示完整的文件,因为它们将存在于git索引中 [英] Show complete files as they would exist in the git index

查看:112
本文介绍了显示完整的文件,因为它们将存在于git索引中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个预先提交的钩子,并希望检查每个即将提交的文件的全部内容(特别是对这些文件进行的lint检查)。我想lint检查文件,因为它会被提交,而不是它存在于我的工作树中(这可能会有所不同)。



预提交钩子示例git会告诉你如何获得diff(所以你可以检查空格等),但是我需要获取整个文件,因为它会被提交。

解决方案

试试这个:

  git --work-tree = / path / to / checkout-area checkout-index path / to / file-to-checkout 

- work-tree 选项告诉git使用不同的区域作为工作树,这样就不会覆盖真正的工作树中的文件。您可能还想添加 -f 选项以在必要时指示它被覆盖,但是如果您的脚本自行清理完毕,则不需要。请参阅检视索引手册页了解更多信息。

I'm writing a pre-commit hook, and would like to do a check on the entire contents of each file that's about to be committed (specifically a lint check on the files). I want to lint check the file as it's going to be commited, not as it exists in my working tree (which may differ).

The pre-commit hook example that comes with git shows you how to get the diff (so you can examine for spaces and such), but I need to get the entire file as it's going to be committed.

解决方案

Try this:

git --work-tree=/path/to/checkout-area checkout-index path/to/file-to-checkout

The --work-tree option tells git to use a different area as the work tree, so that you don't overwrite the file in your true work-tree. You might also want to add the -f option to tell it to overwrite if necessary, but if your script properly cleans up after itself it shouldn't be necessary. See the man page for checkout-index for more information.

这篇关于显示完整的文件,因为它们将存在于git索引中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆