Reputation: 1042
I would like to order some output of git log by date (not by time)
Unfortunately it seems to be impossible to sort only by some characters, ignoring the rest of the line with sort
. What I tried so far:
Input: git-log.txt
git log --date-order --reverse --show-all --pretty="%ai#%h %s"
2013-08-22 09:54:12 +0200#f03fec1 G
2013-08-21 10:43:57 +0200#c026cd6 A
2013-08-21 10:49:58 +0200#4630c3f B
2013-08-21 11:14:42 +0200#6e7141d C
2013-08-21 13:02:59 +0200#23ab0a8 D
2013-08-21 10:39:23 +0200#06b83f7 E
2013-08-21 14:10:16 +0200#f53384e F
2013-08-20 16:22:33 +0200#12591fb Z
naiv: This will sort perfectly including date
sort -k 1.1,1.10 git-log.txt
tricking by solving ties with not existing column
sort -k 1.1,1.10 -k 200 git-log.txt
tricking it to interpret whole line as single column with not existing separation character
sort -k 1.1,1.10 -t "^" git-log.txt
in all cases, output is:
2013-08-20 16:22:33 +0200#12591fb Z
2013-08-21 10:39:23 +0200#06b83f7 E
2013-08-21 10:43:57 +0200#c026cd6 A
2013-08-21 10:49:58 +0200#4630c3f B
2013-08-21 11:14:42 +0200#6e7141d C
2013-08-21 13:02:59 +0200#23ab0a8 D
2013-08-21 14:10:16 +0200#f53384e F
2013-08-22 09:54:12 +0200#f03fec1 G
I need (see the position of commit E)
2013-08-20 16:22:33 +0200#12591fb Z
2013-08-21 10:43:57 +0200#c026cd6 A
2013-08-21 10:49:58 +0200#4630c3f B
2013-08-21 11:14:42 +0200#6e7141d C
2013-08-21 13:02:59 +0200#23ab0a8 D
2013-08-21 10:39:23 +0200#06b83f7 E
2013-08-21 14:10:16 +0200#f53384e F
2013-08-22 09:54:12 +0200#f03fec1 G
How to teach sort
to keep sort order on a tie?
I can add any needed character the output...
Upvotes: 0
Views: 66
Reputation: 31728
Note also the sort --debug option to help with this (it would have made the second problematic sort obvious in this case)
Upvotes: 1
Reputation: 123508
You seem to be looking for -s
option for sort
:
-s, --stable
stabilize sort by disabling last-resort comparison
Say
sort -k 1.1,1.10 -t "^" -s git-log.txt
instead.
Upvotes: 1