Git 过滤分支不会重写所有历史记录

发布于 2025-01-03 15:26:25 字数 1401 浏览 1 评论 0原文

我正在尝试使用以下命令重写存储库的历史记录:

git filter-branch -f --env-filter '
        an="$GIT_AUTHOR_NAME"
        am="$GIT_AUTHOR_EMAIL"
        cn="$GIT_COMMITTER_NAME"
        cm="$GIT_COMMITTER_EMAIL"

        if [[ "$GIT_COMMITTER_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"

        fi

        if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"
        fi

        export GIT_AUTHOR_NAME="$an"
        export GIT_AUTHOR_EMAIL="$am"
        export GIT_COMMITTER_NAME="$cn"
        export GIT_COMMITTER_EMAIL="$cm"'
 -- --all

该命令运行良好,并按指定重写作者。问题是它似乎遗漏了历史中的一些条目。我认为当分支中所做的更改被合并时就会发生这种情况,但我不确定。

注意:这是使用Git+SVN导入到Git的SVN存储库。

I'm trying to re-write a repo's history using:

git filter-branch -f --env-filter '
        an="$GIT_AUTHOR_NAME"
        am="$GIT_AUTHOR_EMAIL"
        cn="$GIT_COMMITTER_NAME"
        cm="$GIT_COMMITTER_EMAIL"

        if [[ "$GIT_COMMITTER_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"

        fi

        if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"
        fi

        export GIT_AUTHOR_NAME="$an"
        export GIT_AUTHOR_EMAIL="$am"
        export GIT_COMMITTER_NAME="$cn"
        export GIT_COMMITTER_EMAIL="$cm"'
 -- --all

The command runs fine, and rewrites the author as specified. The problem is that it seems to miss some entries in the history. I think it's happening when changes made in a branch were merged in, but I'm not sure.

Note: This is an SVN repository that was imported into Git using Git+SVN.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2025-01-10 15:26:25

我不认为你的条件正在检查你想要什么。不应该:

if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]

if [[ "$GIT_AUTHOR_EMAIL" =~ "jacks.*" ]]

注意:这只适用于 Bash 3.0 或更高版本。否则,我认为您需要使用 grep 或 sed 外部命令作为条件检查的一部分。

另外,我认为只有当提交者的电子邮件不是 Jack 时才需要更改提交者,反之亦然。因此,请确保删除提交者电子邮件检查中的 anam 分配,并对作者电子邮件检查进行类似的修复。

I don't think your conditionals are checking what you want. Shouldn't:

if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]

be

if [[ "$GIT_AUTHOR_EMAIL" =~ "jacks.*" ]]

Note: this will only work in Bash 3.0 or higher. Otherwise I think you'll need to use grep or sed external commands as part of your conditional checks.

Also, I think you will only want to change the commiter when the commiter's email isn't Jack's and vice versa for the author. So make sure you take out your an and am assignments in your comitter email check and make the similar fix to your author email check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文