1

I need to check the location of the files, which were changed in the last commit. Because I will have to do this on Jenkins, this should be done using a bash script. This is the output of git whatchanged -n 1 (the command I want to use for this)

lukas @ leaf (~/workspace/shairweb) 🐌  git whatchanged -n 1
commit b4818eca9252c4a218cafefdf99540e4ebfd306d
Author: Lukas Fülling <lukas@mailprovider.com>
Date:   Tue Nov 18 13:13:43 2014 +0100

    Initial release

:000000 100644 0000000... bfa384f... A  pom.xml
:000000 100644 0000000... 370e9a1... A  shairweb.iml
:000000 100644 0000000... 5e513a6... A  src/main/java/net/k40s/shairplay/APIResource.java
:000000 100644 0000000... 45f03cb... A  src/main/java/net/k40s/shairplay/FileParser.java
:000000 100644 0000000... 82aab5b... A  src/main/java/net/k40s/shairplay/Main.java
:000000 100644 0000000... 20d5340... A  src/test/java/net/k40s/shairplay/APIResourceTest.java

I tried doing this using grep but I believe there is a better way for doing this. How else can I parse it to get something like:

src/test/java/net/k40s/shairplay/
1

Try this way:

LASTCOMMIT=$(git log -1 --oneline | cut -f1 -d" ")
git diff-tree --no-commit-id --name-only -r $LASTCOMMIT
  • What about simply using HEAD in place of $LASTCOMMIT? – chepner Nov 19 '14 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.