@@ -18,6 +18,7 @@ no-rebase Don't do a rebase after commit
1818n,no-verify Bypass the pre-commit and commit-msg hooks
1919b,base=rev Use <rev> as base of the revision range for the search
2020A,all Show all candidates
21+ r,reverse Reverse the sort
2122"
2223# shellcheck disable=SC2034
2324SUBDIRECTORY_OK=yes
@@ -69,7 +70,7 @@ print_sha () {
6970 local sha=$1
7071 local type=$2
7172
72- git --no-pager log --format=" %H [$type ] %s <%ae>" -n 1 " $sha "
73+ git --no-pager log --format=" %h %ai [$type ] %s <%ae>" -n 1 " $sha "
7374}
7475
7576# Call git commit
@@ -164,6 +165,11 @@ show_menu () {
164165 fi
165166}
166167
168+ sort_commits () {
169+ # shellcheck disable=SC2086
170+ sort $sort_flags $additional_sort_flags
171+ }
172+
167173git_commit_args=()
168174target=
169175op=${GITFIXUPACTION:- $(git config --default=fixup fixup.action)}
@@ -172,7 +178,8 @@ fixup_menu=${GITFIXUPMENU:-$(git config --default="" fixup.menu)}
172178create_commit=${GITFIXUPCOMMIT:- $(git config --default=false --type bool fixup.commit)}
173179base=${GITFIXUPBASE:- $(git config --default=" " fixup.base)}
174180show_all=false
175-
181+ sort_flags=" -k2 -k3 -k4" # default flags to sort by time (eg 2025-01-03 10:04:43 +0100, hence 3 fields)
182+ additional_sort_flags=${GITFIXUPADDITIONALSORTFLAGS:- $(git config --default=" " fixup.additionalSortFlags)}
176183while test $# -gt 0; do
177184 case " $1 " in
178185 -s|--squash)
@@ -209,6 +216,9 @@ while test $# -gt 0; do
209216 -A|--all)
210217 show_all=true
211218 ;;
219+ -r|--reverse)
220+ additional_sort_flags=" -r"
221+ ;;
212222 --)
213223 shift
214224 break
264274fi
265275
266276if test " $create_commit " = " true" ; then
267- target=$( print_candidates | show_menu)
277+ target=$( print_candidates | sort_commits | show_menu)
268278 if test -z " $target " ; then
269279 exit
270280 fi
@@ -273,5 +283,5 @@ if test "$create_commit" = "true"; then
273283 call_rebase " ${target%% * } "
274284 fi
275285else
276- print_candidates
286+ print_candidates | sort_commits
277287fi
0 commit comments