如何在git add之前自动调用脚本? [英] How to automatically invoke a script before a git add?

查看:121
本文介绍了如何在git add之前自动调用脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的用例:我在Git存储库中提交了PNG和其他内容.我想对要提交的每个PNG应用特定的过程,这是我最终要提交的过程的结果(潜在的经过修改的PNG).

在一开始,我想到了一个钩子(例如pre-commit),但这有点奇怪,因为该过程将更改文件,因此我需要重新添加它!根据我已阅读的内容,没有pre-add钩子(或那样的东西.)

可能的解决方案是创建git别名?但是我不想(太多)改变人们的工作方式,我在寻找一种光滑透明的方法.

如果您有线索...即使线索是要改变我的流程想法.

解决方案

您可能想考虑一下污渍&干净的过滤器,在git add期间应用clean,在结帐期间应用污迹.这些可以按文件类型分配.查看"git attributes(5)"手册页和 Git SCM书:Git属性./p>

Here's my use case: I commit PNGs and other stuff in my Git repo. I would like to apply a specific process to every PNGs I would like to commit and this is the result of the process I finally want to commit (the potential modified PNG).

At the beginning I thought about a hook (like a pre-commit) but it's a little weird because the process will change the file so I will need to re-add it! And according to what I read, there is no pre-add hook (or something like that).

May be a solution is to create a git alias ? But I don't want to change - too much - the way people work, I'm searching for a smooth and transparent way.

If you have a clue... even if the clue is to change my process idea.

解决方案

You may want to consider a smudge & clean filter, with the clean being applied during the git add, and the smudge during checkout. These can be allocated by file type. Look at the 'git attributes(5)' man page and Git SCM book : Git Attributes.

这篇关于如何在git add之前自动调用脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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