git hooks - regenerate a file and add it to each commit?

一个人想着一个人 提交于 2019-12-04 04:04:28

问题


I'd like to automatically generate a file and add it to a commit if it has changed. Is it possible, if so, what hooks should I use?

Context: I'm programming a CSS library. It has several CSS files, and at the end I want to produce a compacted and minimized version. Right now my workflow is:

  1. Modify the css files x.css and y.css
  2. git add x.css y.css
  3. Execute minimize.sh which parses all the css files on my lib, minimizes them and produces a min.css file
  4. git add min.css
  5. git commit -m 'modified x and y doing foo and bar'

I would like to have steps 3 and 4 done automatically via a git hook. Is that possible?

I've never used git hooks before. After reading the man page, I think I need to use the pre-commit hook. But can I invoke git add min.css, or will I break the internet?

EDIT: It worked! And I didn't create a black hole or anything!

Here's the code of my .git/hooks/pre-commit file:

#!/bin/sh
exec minimize.sh
exec git add oocss.min.css

The documentation didn't mention that I had to make it executable, or it would not work.

In case you are interested in how did I minimize, I used juicer - the minimizing command is:

exec juicer merge --force my-uncompressed-file.css

回答1:


No, it won’t break anything. You can freely use git add in a pre-commit hook.



来源:https://stackoverflow.com/questions/4532192/git-hooks-regenerate-a-file-and-add-it-to-each-commit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!