Anonymous
Anonymous

Reputation: 3414

Git log --pretty=format with lines added and removed?

I'd like to have a flag like:

git log --pretty="format: %added %removed %cd"

As far as I can see those flags are not available in format:<string>.

I've read the documentation and it doesn't seem to exist, but it seems like such an obvious thing to include that I'm wondering if I am missing something.

Upvotes: 4

Views: 2305

Answers (1)

VonC
VonC

Reputation: 1328152

If you need to script it in order to display what you want, the closest native git command which display the lines added/removed per files in git log is:

git log --pretty=tformat: --numstat

With:

--numstat

Similar to --stat, but shows number of added and deleted lines in decimal notation and pathname without abbreviation, to make it more machine friendly.
For binary files, outputs two - instead of saying 0 0.

This gist by KOGI provides one example of such a script (not exactly what you are after, but you get the general idea)

git log --pretty=tformat: --numstat $@ "`git merge-base HEAD develop`..HEAD" | gawk '{ adds += $1 ; subs += $2 ; net += $1 - $2 ; gross += $1 + $2 ; commits += 1 } END { print "total commits\tadded loc\tremoved loc\tgross loc\tnet loc\n"; printf "%d\t%d\t%d\t%d\t%d\n", commits, adds, subs, gross, net }' | column -s $'\t' -t

Upvotes: 2

Related Questions