通过 git hook 缩小 CSS 文件
我的理想情况是自动缩小 CSS 文件并将它们添加到 git 提交中。我不确定是否可以完成下面的#4,但我希望执行以下流程:
- 修改CSS文件
- 添加到暂存区域
- 提交
- 运行更新缩小文件并将其添加到提交的脚本
- 提交完成
如果有其他方法,我也会对此感兴趣。
My ideal situation is to automatically minify CSS files and add them to the git commit. I'm not sure if #4 below can be done, but I would like the following flow to be performed:
- Modify CSS file
- Add to staging area
- Commit
- Run script that updates the minified files and adds them to the commit
- Commit completes
If there is another way, I'd be interested in that as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是否应该是另一回事,但你可以。
在 .git/hooks/ 中,用您选择的语言编写一个名为 pre-commit 的脚本(确保它是可执行的)
在该脚本中,运行您的 minifier 命令,然后执行“git add”,
这是一个以这种方式缩小 javascript 的示例:
https://gist.github.com/786460
我编写的测试钩子:
运行提交后,test1_diff .css 位于工作目录中,并在 git 中进行跟踪。
Whether you should is another matter, but you can.
in .git/hooks/, write a script in your language of choice (make sure it's executable) named pre-commit
in that script, run your minifier command, and do 'git add '
here's an example of someone who minifies javascript this way:
https://gist.github.com/786460
a test hook I wrote:
after running the commit, test1_diff.css was in the working directory, and in git, tracked.
您将使用“预提交挂钩”,该挂钩在实际提交之前/进行时被调用。谷歌一下——它基本上只是将一个
预提交
脚本文件放入您的.git
文件夹中。You would use a "pre-commit hook" which gets called before/as your actual commit is made. Google it -- it basically just involved putting a
pre-commit
script file in your.git
folder.编写一个涂抹/清理脚本并使用过滤器属性标记您的CSS文件。诀窍是在不具有该属性的分支上完成工作,并从具有该属性的分支进行部署。如果您最初使用我们的合并策略从部署分支进行反向合并,那么设置起来很容易。这可确保后续合并不会传播该属性。
那应该做你想做的事。
Write a smudge/clean script and mark your css files with the filter attribute. The trick is to do the work on a branch that does not have the attribute and deploy from the one that does. This is easy to set up if you back merge from the deploy branch initially with an ours merge strategy. This ensures that subsequent merges don't propagate the attribute.
That should do what you want.