3

I am using the following Git command to get the data about a particular commit:

  git show <revhash> --stat >> ouput.csv

This is the output I get:

  commit 7bc745a289cf68cb2eba647bbfba9e9ec06eb771
  Author: Stefan Bodewig <bodewig@apache.org>
  Date:   Mon Jun 24 15:12:57 2013 +0000

post-process generated javadocs as workaround for CVE-2013-1571 - based on Maven patch by Uwe Schindler - PR 55132

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1496083 13f79535-47bb-0310-9956-ffa450edef68

   CONTRIBUTORS                                       |   1 +
   WHATSNEW                                           |   9 ++
   contributors.xml                                   |   4 +
   manual/Tasks/javadoc.html                          |  12 +++
   .../org/apache/tools/ant/taskdefs/Javadoc.java     | 111 ++++++++++++++++++++-
   .../ant/taskdefs/javadoc-frame-injections-fix.txt  |  37 +++++++
   6 files changed, 171 insertions(+), 3 deletions(-)

I would like to get the list of files changed like this without the other metadata in the following way:

  1 file changed, 1 insertion(+), 1 deletion(-)

I know I can use --shortstat, but it still gives other information such as commit hash, date e.t.c

I think there can be no such thing in git, but what would be the smartest way to parse the output of the last line then?

lowlypalace
  • 137
  • 2
  • 9

3 Answers3

5

I would use --format

git show <commit> --shortstat --format="" >>output.csv
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • This *also* works, but produces no output at all for a merge commit. Add `-m` and it produces one diff short-stat per parent, which may or may not be desirable. – torek Nov 30 '18 at 20:05
1
git diff --shortstat HEAD^!

The ^! suffix basically says "compare HEAD with the parent of HEAD

A.H.
  • 63,967
  • 15
  • 92
  • 126
  • That does work, but it's because of a sort-of-bug in `git diff`. `^!` is described in gitrevisions as `the same as giving commit and then all its parents prefixed with ^ to exclude them (and their ancestors).` The internal code for `git diff` uses `B ^A` or `^A B` to mean `git diff A B`. When it hits a merge, though, it gets `git diff ^A ^B ^C D` and you wind up with `^A D` here. – torek Nov 30 '18 at 19:38
  • Anyway, the upshot is: this works, even for merges, but you might want to be more explicit by writing `git diff ^ ` or similar, to note that you are comparing the first parent of the commit, to the commit. If the commit is a merge (with N>1 parents) you're explicitly ignoring all but the first. The `git diff` command might someday warn or error for this case, or attempt a combined diff instead of a regular diff, or some such. – torek Nov 30 '18 at 20:03
0

Use tail to cut off everything besides the last 1 line:

git show <commit> --shortstat | tail -n1
alfunx
  • 3,080
  • 1
  • 12
  • 23