Git:提交日期的批量更改 [英] Git: Bulk change of commit dates

查看:282
本文介绍了Git:提交日期的批量更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要更改各种提交的提交日期时,我会使用交互式基准,并逐一更改它们.

When I need to change the commit dates of various commits, I use an interactive rebase and change them one by one.

如何在一个命令中将它们全部更改?换句话说,我需要将给定命令应用于将在交互式资源库中列出的所有提交.

How could I change them all in a single command ? In other words, I need to apply a given command to all commits that would be listed in an interactive rebase.

谢谢

推荐答案

Filter-Repo

git filter-branch已过时.而是使用git filter-repo.您将需要安装它.

Filter-Repo

git filter-branch is deprecated. Instead, use git filter-repo. You will need to install it.

这是优秀文章使用git-filter-repo修改提交日期. git-filter-repo文档很好地解释了--commit-callback的概念.

Here is an excellent article about how to use git-filter-repo to modify the commit date. The git-filter-repo documentation explains the concept of --commit-callback pretty well.

让我们将所有提交日期的时区重置为零.

Let's reset the timezone of all commit dates to zero.

# Save this as ../change_time.py
def handle(commit):
    "Reset the timezone of all commits."
    date_str = commit.author_date.decode('utf-8')
    [seconds, timezone] = date_str.split()
    new_date = f"{seconds} +0000"
    commit.author_date = new_date.encode('utf-8')

handle(commit)

# You need to be in a freshly-cleaned repo. Or use --force.
git clone <...> your_repo
cd your_repo
# First just a dry run.
git filter-repo --dry-run --commit-callback "$(cat ../change_time.py)"
# And now do it for real
git filter-repo --commit-callback "$(cat ../change_time.py)"

这篇关于Git:提交日期的批量更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆