-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-sorthist
More file actions
executable file
·63 lines (55 loc) · 2.35 KB
/
git-sorthist
File metadata and controls
executable file
·63 lines (55 loc) · 2.35 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
#/***************************************************************************
# * Copyright (C) 2016-2023 Daniel Mueller (deso@posteo.net) *
# * *
# * This program is free software: you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation, either version 3 of the License, or *
# * (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program. If not, see <http://www.gnu.org/licenses/>. *
# ***************************************************************************/
set -u -o pipefail
if [ ${#} -ne 1 ]; then
echo "Usage: $(basename ${0}) <sha1>"
exit 1
fi
# We need a temporary file for our purposes.
file="$(mktemp)"
# Now, put all the dates of commits in the current branch that we want
# to rebase into this file, in a sorted fashion.
git log --date=iso --format=format:'%ad' ${1}..HEAD | sort > "${file}"
if [ ${?} -ne 0 ]; then
echo "git log failed"
rm -f "${file}"
exit 1
fi
# Last we get to the real fun. Rebase everything, adjust the author
# date using the first date in the temporary file. Afterwards, remove
# this very date.
cmd=" \
date=\"\$(head -n1 ${file} | tr -d '\n')\"; \
GIT_AUTHOR_DATE=\"\${date}\" \
GIT_COMMITTER_DATE=\"\${date}\" \
GPG_SIGNATURE_TIMESTAMP=\$(date --date=\"\${date}\" +'%s') \
git commit --amend --reuse-message=HEAD --date=\"\${date}\"; \
sed -i '1d' \"${file}\" \
"
git rebase --interactive --keep-empty --exec="${cmd}" ${1}
if [ ${?} -eq 0 ]; then
# The file should be empty.
if [ ! -z "$(cat ${file})" ]; then
echo "${file} not empty; error in script"
exit 1
else
rm -f "${file}"
fi
else
rm -f "${file}"
fi