2

I'm trying to set up a file that list all of the files in a project that was modified.

I want this to be done automatically whenever I commit. I tried playing around with all of the git log commands but still no luck.

I'm doing this to signal to the server which files need re-minification after the server does a checkout on the repo.

EDIT: This is my script so far:

FILES="$(find /home/qwertymk/public_html -type f -name '*.js')"
CHANGED="git whatchanged -n 1 --pretty=format:"
for f in $FILES
do
 if [[ $f =~ /home/torah/public_html/ignore-folder/ ]]; then continue; fi
 if [[ $f =~ $CHANGED ]]; then continue; fi  # What do I do here?
  echo "processing - $f"
  php /home/qwertymk/jsmin/curl.php $f
done
qwertymk
  • 34,200
  • 28
  • 121
  • 184

1 Answers1

3

Instead of saving the list of modified files in the commit message, you can query git directly for this information using git-whatchanged. To get a list of changes for the latest commit you can do:

git whatchanged -n 1

To get a list of changes between two named commits, you can do:

git whatchanged <since>..<until>

You can also get this info from git-log like this, including whatever other git-log options you want:

git log --name-status <options>

Following the notes in the comments, this probably gets you the information you need distilled down to nearly only what you need:

git log --name-status --pretty=format: -n 1

(Replace -n 1 with whatever you need to specify the commits)

Ben Lee
  • 52,489
  • 13
  • 125
  • 145
  • 1
    Those commands include the full filelist. You can use a simple regex or other text process to pull them out. – Ben Lee Feb 20 '12 at 13:08
  • 1
    Note you can also use `--pretty=oneline` (or `--oneline`) to minimize the amount of superfluous information returned. – Ben Lee Feb 20 '12 at 13:09
  • 1
    You can even use `--pretty=format:` (with an empty format specification) to just show a blank line for the commit info, leaving you with just the changes files. – Ben Lee Feb 20 '12 at 13:14
  • How would I incorporate that into my script? (I edited the question). – qwertymk Feb 20 '12 at 18:01
  • @qwertymk, can you post a new stackoverflow question detailing the question about scripting? That's really a separate question from the git log question, and someone else might be able to help you with bash scripting more than I can. I know git (and I believe I answered the git question with the best method), but I use ruby for all my scripting purposes so don't know how much I can help you with that script. – Ben Lee Feb 20 '12 at 23:06