threads / discuss / 49599

Sort output of diff --stat?

Subject: Sort output of diff --stat?

## tl;dr

4 messages between Oct 17, 2018 and Oct 17, 2018.

replies: 3people: 2as markdown or json

Robert Dailey· Oct 17, 2018, 18:15 UTC · lore

I'd like to sort the output of `git diff --stat` such that files are listed in descending order based on number of lines changed. The closest solution I've found online[1] has several readability issues. I'd rather see a built-in solution in git, if one exists. Can anyone recommend a solution?

[1]: https://gist.github.com/jakub-g/7599177
Jeff King· Oct 17, 2018, 18:47 UTC · re: Robert Dailey · lore

Re: Sort output of diff --stat?

On Wed, Oct 17, 2018 at 01:15:18PM -0500, Robert Dailey wrote:
Show 5 quoted lines
> I'd like to sort the output of `git diff --stat` such that files are
> listed in descending order based on number of lines changed. The
> closest solution I've found online[1] has several readability issues.
> I'd rather see a built-in solution in git, if one exists. Can anyone
> recommend a solution?

Hmm, I feel like another person asked for this recently, but I can't seem to find the thread.

Anyway, no, I don't think there's a solution short of parsing the output (you could parse --numstat, which is at least sane, but then you'd have to generate your own visual diffstat, which has a lot of corner cases).

We have --orderfile, but that's about a static order based on filename. It seems reasonable to me for "--stat" to learn an option to sort (that would not affect, say, the total diff order, since sorting by line count makes very little sense for most other formats).

-Peff
Robert Dailey· Oct 17, 2018, 19:21 UTC · re: Jeff King · lore

Re: Sort output of diff --stat?

On Wed, Oct 17, 2018 at 1:47 PM Jeff King <peff@peff.net> wrote:
> Hmm, I feel like another person asked for this recently, but I can't
> seem to find the thread.

Is it this one? https://www.mail-archive.com/git@vger.kernel.org/msg159212.html

That's the only one I was able to find, but no one replied. Thanks for your insight. I didn't get my hopes up, but maybe someday it'll be added.

Jeff King· Oct 17, 2018, 19:25 UTC · re: Robert Dailey · lore

Re: Sort output of diff --stat?

On Wed, Oct 17, 2018 at 02:21:57PM -0500, Robert Dailey wrote:
Show 10 quoted lines
> On Wed, Oct 17, 2018 at 1:47 PM Jeff King <peff@peff.net> wrote:
> > Hmm, I feel like another person asked for this recently, but I can't
> > seem to find the thread.
> 
> Is it this one?
> https://www.mail-archive.com/git@vger.kernel.org/msg159212.html
> 
> That's the only one I was able to find, but no one replied. Thanks for
> your insight. I didn't get my hopes up, but maybe someday it'll be
> added.

Ah, yeah, that's the one. For some reason I thought I had replied, but obviously I did not. ;)

-Peff

← back to recent threads