Git hooks - restore file and add it to each commit?

I would like to automatically generate the file and add it to commit if it has changed. Is it possible, if so, which hooks should I use?

Context: I am programming a CSS library. It has several CSS files, and in the end I want to create a compact and minimized version. Now my workflow:

  • Change css files x.cssandy.css
  • git add x.css y.css
  • Run minimize.sh, which parses all css files in my library, minimizes them and creates a filemin.css
  • git add min.css
  • git commit -m 'modified x and y doing foo and bar'

I would like steps 3 and 4 to be executed automatically with a git hook. Is it possible?

I have never used git hooks before. After reading the man page , I think I need to use pre-commithook. But can I call git add min.css, or will I break the Internet?

EDITOR: It worked! And I did not create a black hole or anything else!

Here is the code for my .git / hooks / pre-commit file:

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

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

If you are interested in how I minimized, I used juicer - the minimize command:

exec juicer merge --force my-uncompressed-file.css
+3
source share
1 answer

No, he will not break anything. You are free to use git addat pre-commit.

+4
source

Source: https://habr.com/ru/post/1782127/


All Articles