4

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 <[email protected]> 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?

1

3 Answers 3

5

I would use --format

git show <commit> --shortstat --format="" >>output.csv 
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1
git diff --shortstat HEAD^! 

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

2 Comments

That does work, but it's because of a sort-of-bug in git diff. <rev>^! is described in gitrevisions as the same as giving commit <rev> 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.
Anyway, the upshot is: this works, even for merges, but you might want to be more explicit by writing git diff <rev>^ <rev> 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.
0

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

git show <commit> --shortstat | tail -n1 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.