-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-reorder
executable file
·27 lines (25 loc) · 1.26 KB
/
git-reorder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
#
# Update the author timestamps on commits so they are in order.
# When you re-order commits with git-rebase --interactive, the author
# timestamp is preserved. However, github orders commits based on the
# author timestamp so it does not show then in graph order in the UI.
# This script updates the author timestamp of the commits on a branch
# to be in order so github shows it in the correct order.
# We cannot just use `git rebase --ignore-date` as that will usually
# set the author date of each commit to be the same, and github seems
# to be non-determinstic in the order it shows these. Instead we want
# each commit to be 1 second later than the previous.
#
# Note: This uses `git merge-base --fork-point` to determine the base
# for the rebase. This works from the reflog so really only works on
# branches you have created in this repo. But if you are reworking the
# commits, that is likely.
branch="${1:-$(git config --get --default master init.defaultBranch)}"
fork_point=$(git merge-base --fork-point "${branch}")
num_commits=$(git rev-list --count "${fork_point}"..)
now=$(date +%s)
date_subst="\$(($now - $num_commits + \$(git rev-list --count ${fork_point}..)))"
git rebase \
--exec "git commit --amend --no-edit --date=\"${date_subst}\"" \
"${fork_point}"