gpt4 book ai didi

git - 如何将文件推送到过去的时间?

转载 作者:行者123 更新时间:2023-12-02 14:25:32 26 4
gpt4 key购买 nike

昨天,我对项目文件进行了更改,但忘记提交并将其推送到 github 上。我不希望我的连续贡献在 51 天后中断......所以我想将该 promise 推迟到昨天,以便我的连续贡献继续......这可能吗?

提前非常感谢您!

最佳答案

我的路径中有该脚本,名为 git-rcd ,这会更改您想要的任何提交(不仅仅是最后一个提交)的 GIT_COMMITTER_DATEGIT_AUTHOR_DATE

#!/bin/bash
# commit
# date YYYY-mm-dd HH:MM:SS

commit="$1" datecal="$2"
temp_branch="temp-rebasing-branch"
current_branch="$(git rev-parse --abbrev-ref HEAD)"

date_timestamp=$(date -d "$datecal" +%s)
date_r=$(date -R -d "$datecal")
echo "datecal=$datecal => date_timestamp=$date_timestamp date_r=$date_r"

if [[ -z "$commit" ]]; then
exit 0
fi

git checkout -b "$temp_branch" "$commit"
GIT_COMMITTER_DATE="$date_timestamp" GIT_AUTHOR_DATE="$date_timestamp" git commit --amend --no-edit --date "$date_r"
git checkout "$current_branch"
git rebase --autostash --committer-date-is-author-date "$commit" --onto "$temp_branch"
git branch -d "$temp_branch"

这允许我获取我刚刚所做的最后一次提交并输入:

git rcd @ '1 day ago'

然后很快!我的最后一次提交已于昨天完成。

它会更改您想要的任何提交:

git rcd @~2 '1 day ago'

这只会更改 HEAD~2(而不是 HEAD~HEAD)

该脚本甚至可以在 Windows 上运行。

更改完成后,推送(如果您之前推送的日期错误,则推送git push --force)。并且您的连胜记录将被保留。

<小时/>

注释(2020),David Fullerton提到in the comments :

Getting this working on Mac OS X required:

关于git - 如何将文件推送到过去的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24722637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com