使用 Git SVN 追溯纠正作者?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/392332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:07:34  来源:igfitidea点击:

Retroactively Correct Authors with Git SVN?

svngitgit-svn

提问by Daniel Spiewak

I have a repository which I have alreadycloned from Subversion. I've been doing some work in this repository in its Git form and I would hate to lose that structure by cloning again.

我有一个已经从 Subversion 克隆的存储库。我一直在以 Git 形式在这个存储库中做一些工作,我不想通过再次克隆而丢失该结构。

However, when I originally cloned the repository, I failed to correctly specify the svn.authorsproperty (or a semantically-similar option).

但是,当我最初克隆存储库时,我未能正确指定svn.authors属性(或语义相似的选项)。

Is there any way I can specify the SVN author mappings now that the repository is fully Git-ified?

既然存储库是完全 Git 化的,有什么方法可以指定 SVN 作者映射吗?

Preferably, I would like to correct all of the old commit authors to represent the Git author rather than the raw SVN username.

最好,我想更正所有旧的提交作者以代表 Git 作者而不是原始 SVN 用户名。

回答by Dustin

Start out by seeing what you've got to clean up:

首先查看您必须清理的内容:

git shortlog -s

For each one of those names, create an entry in a script that looks like this (assuming you want all the authors and committers to be the same):

对于这些名称中的每一个,在脚本中创建一个条目,如下所示(假设您希望所有作者和提交者都相同):

#!/bin/sh

git filter-branch --env-filter '

n=$GIT_AUTHOR_NAME
m=$GIT_AUTHOR_EMAIL

case ${GIT_AUTHOR_NAME} in
        user1) n="User One" ; m="[email protected]" ;;
        "User Two") n="User Two" ; m="[email protected]" ;;
esac

export GIT_AUTHOR_NAME="$n"
export GIT_AUTHOR_EMAIL="$m"
export GIT_COMMITTER_NAME="$n"
export GIT_COMMITTER_EMAIL="$m"
'

That's basically the script I used for a large rewriterecently that was very much as you described (except I had large numbers of authors).

这基本上是我最近用于大型重写的脚本,与您描述的非常相似(除了我有大量作者)。

editUse π pointed out a quoting problem in my script. Thanks!

编辑使用 π 指出了我脚本中的一个引用问题。谢谢!

回答by J?rg W Mittag

git filter-branchcan be used to rewrite large chunks of history.

git filter-branch可用于重写大量历史记录。

In this case, you would probably do something like (totally untested):

在这种情况下,您可能会执行以下操作(完全未经测试):

git filter-branch --env-filter '
    GIT_AUTHOR_NAME=`echo "${GIT_AUTHOR_NAME}" | sed -e "s/svnname1/Right Name/; s/svnname2/Correct Name/"`
    GIT_COMMITTER_NAME=`echo "${GIT_COMMITTER_NAME}" | sed -e "s/svnname1/Right Name/; s/svnname2/Correct Name/"`
    GIT_AUTHOR_EMAIL=`echo "${GIT_AUTHOR_EMAIL}" | sed -e "s/svnname1/[email protected]/; s/svnname2/[email protected]/"`
    GIT_COMMITTER_EMAIL=`echo "${GIT_COMMITTER_EMAIL}" | sed -e "s/svnname1/[email protected]/; s/svnname2/[email protected]/"`
'

As always, the following applies: in order to rewrite history, you need a conspiracy.

与往常一样,以下内容适用:为了改写历史,你需要一个阴谋

回答by Greg Hewgill

You probably want to look into git-filter-branch, specifically the --commit-filteroption. This command is a powerful chainsaw that can rewrite your entire repository history, changing whatever you might want to change.

您可能想要查看git-filter-branch,特别是--commit-filter选项。这个命令是一个强大的电锯,可以重写你的整个存储库历史,改变你可能想要改变的任何东西。

Note that when you do this, you should pull new clones from the updated repository since the SHA1 hashes of every commit may have changed.

请注意,执行此操作时,您应该从更新的存储库中提取新的克隆,因为每次提交的 SHA1 哈希值可能已更改。