在保留提交时间戳的同时执行git rebase是否有意义?
我相信结果将是新的分支不一定有按时间顺序提交的日期。这在理论上可行吗?(例如使用管道命令;只是好奇)
如果这在理论上是可能的,那么在实践中是否可能使用rebase而不更改时间戳?
例如,假设我有以下树:
master <jun 2010>
|
:
:
: oldbranch <feb 1984>
: /
oldcommit <jan 1984>
现在,如果我在master上重新创建oldbranch,提交的日期从1984年2月更改为2010年6月。是否有可能改变这种行为,从而不改变提交时间戳?最后,我将得到:
oldbranch <feb 1984>
/
master <jun 2010>
|
:
这有意义吗?git中是否允许有历史记录,即旧的提交有最近的提交作为父?
post-rewrite钩
这个钩子适用于所有的git rebase, git pull -rebase和git commit -amend。
. / / post-rewrite hook
set -eu
echo post-rewrite
if [ ! "${CIROSANTILLI_GITHOOKS_DISABLE:-0}" = 1 ]; then
declare -a olds
declare -A oldnew
while IFS= read -r line; do
echo "$line"
old="$(echo "$line" | cut -d ' ' -f1)"
new="$(echo "$line" | cut -d ' ' -f2)"
oldnew[$old]="$new"
olds+=("$old")
news+=("$new")
done
git reset --hard "${news[0]}~"
for old in "${olds[@]}"; do
new="${oldnew[$old]}"
git cherry-pick "$new" &>/dev/null
olddate="$(git log --format='%cd' -n 1 "$old")"
CIROSANTILLI_GITHOOKS_DISABLE=1 \
GIT_COMMITTER_DATE="$olddate" \
git commit \
--amend \
--no-edit \
--no-verify \
&>/dev/null \
;
done
echo
fi
GitHub上游。
别忘了:
chmod +x .git/hooks/post-rewrite
这是一种很好的方法——在选定的回购上默认设置committer-date-is-author-date,直到有人最终修补配置以默认设置它。
它还可以用。committer-date-is-author-date,这似乎不会在git pull时暴露。
参见:
什么git挂钩适用于'git rebase -continue'?
男人githooks
在git 2.19, Ubuntu 18.04上测试。
post-rewrite钩
这个钩子适用于所有的git rebase, git pull -rebase和git commit -amend。
. / / post-rewrite hook
set -eu
echo post-rewrite
if [ ! "${CIROSANTILLI_GITHOOKS_DISABLE:-0}" = 1 ]; then
declare -a olds
declare -A oldnew
while IFS= read -r line; do
echo "$line"
old="$(echo "$line" | cut -d ' ' -f1)"
new="$(echo "$line" | cut -d ' ' -f2)"
oldnew[$old]="$new"
olds+=("$old")
news+=("$new")
done
git reset --hard "${news[0]}~"
for old in "${olds[@]}"; do
new="${oldnew[$old]}"
git cherry-pick "$new" &>/dev/null
olddate="$(git log --format='%cd' -n 1 "$old")"
CIROSANTILLI_GITHOOKS_DISABLE=1 \
GIT_COMMITTER_DATE="$olddate" \
git commit \
--amend \
--no-edit \
--no-verify \
&>/dev/null \
;
done
echo
fi
GitHub上游。
别忘了:
chmod +x .git/hooks/post-rewrite
这是一种很好的方法——在选定的回购上默认设置committer-date-is-author-date,直到有人最终修补配置以默认设置它。
它还可以用。committer-date-is-author-date,这似乎不会在git pull时暴露。
参见:
什么git挂钩适用于'git rebase -continue'?
男人githooks
在git 2.19, Ubuntu 18.04上测试。