Today I thought I was doing a simple operation:
git blame file | sort -k 3
To get all the lines of
file sorted by the date on which they were last changed. Unfortunately it doesn't seem to be sorting it correctly. It does work if I do the following:
git blame file | cut -c 20- | sort
Which just hacks the first part of the line off and then does the sort. The success of this command indicates to me that
sort can in fact do the operation I was trying. Why didn't it work?
Here's an example line from the output of
git blame file:
35d8e9eb (username 2007-01-17 03:58:04 +0000 155) Some text on line 155
Edit: Using any reasonable number besides
3 in the original command line seems to work fine - I can sort by the hash (field 1), the username (field 2), the time of day (field 4), or the line number (field 6), but the date (field 3) doesn't work - I can't identify at all what order it actually ends up in...
Edit 2: I've made a sanitized input file that shows the same problem. Here's
cb7bb041 (eeeeeee 2010-12-14 19:41:18 +0000 42) 35d8e9eb (cccccccc 2007-01-17 03:58:04 +0000 135) d7377fa9 (hhhhhhhh 2010-01-30 04:26:28 +0000 178)
And the output from
sort -k 3 cleaned.txt:
$ sort -k 3 cleaned.txt cb7bb041 (eeeeeee 2010-12-14 19:41:18 +0000 42) 35d8e9eb (cccccccc 2007-01-17 03:58:04 +0000 135) d7377fa9 (hhhhhhhh 2010-01-30 04:26:28 +0000 178)
As you can see the sorting on the date field didn't appear to take place at all. Here's the output from
cut -c 20- cleaned.txt | sort:
$ cut -c 20- cleaned.txt | sort 2007-01-17 03:58:04 +0000 135) 2010-01-30 04:26:28 +0000 178) 2010-12-14 19:41:18 +0000 42)
Sorting on dates in that case works fine! Any suggestions?