简体   繁体   中英

Mapping between git committers and SVN users

I'm using git-svn to store a "staging" version of some SVN repo, where other users are allowed to pull from this staging repo and commit there changes back to it, then the commits on the staging repo are periodically committed the upstream SVN repo.

I want to know if there's a way to map between the git committers' names and SVN usernames, so that their information would be kept intact when committing back to the SVN repo?

Vincent Danen does mention the -A option when using git svn :

So using ~/git as a top-level directory for Git repositories [...] create an authors.txt file.
This file will map the names of Subversion committers to Git authors, resulting in a correct history of the imported Subversion repository.
For projects with a small number of committers, this is quite easy. For larger projects with a lot of committers, this may take some time. The syntax of the file would be:

user = Joe User <user@example.com>
vdanen = Vincent Danen <vdanen@somewhere.com>

The short name is the committer name for Subversion whereas the long form is the user's full name and e-mail address, as used by Git.

The final step is to clone the Subversion repository, which creates a local Git repository based on it. Assuming your repository uses the standards of /trunk, /tags, and /branches, use:

# git svn clone --no-metadata -A authors.txt -t tags -b branches -T trunk https://svn.example.com/svn/repo

-A<filename>
--authors-file=<filename>

Syntax is compatible with the file used by git-cvsimport:

loginname = Joe User <user@example.com>

If this option is specified and git-svn encounters an SVN committer name that does not exist in the authors-file, git-svn will abort operation.
The user will then have to add the appropriate entry.
Re-running the previous git-svn command after the authors-file is modified should continue operation.

config key: svn.authorsfile

This should work for all git-svn commands, including git-svn dcommit (when you push to SVN) (Note: I have not tested it directly though).

Mohammed Gamal does report (in the comments) it is working, but without the --no-metadata option.

a second option is to provide a program / script which solves the mapping.

Very useful if there the number of committers is unknown but might be "generated" from the SVN committer name!

If … SVN committer name that does not exist in the authors-file, git svn will abort operation. The user will then have to add the appropriate entry. Re-running the previous git svn command after the authors-file is modified …

so, therefor we have:

--authors-prog=mapMyCompanyUsers.sh

To not have force every user to checkout / curl / wget'ting the map-Script first, you might provide something like this:

$(tmpMapFile="$TMPDIR/mapSvnUsersAutomatically.$$.sh" && echo -e '#!/bin/sh\necho $1" <"$1"@example.com>"' > $tmpMapFile && chmod +x $tmpMapFile && echo $tmpMapFile)

The clone will look like:

$ git svn clone -s --authors-prog=$(tmpMapFile="$TMPDIR/mapSvnUsersAutomatically.$$.sh" && echo -e '#!/bin/sh\necho $1" <"$1"@example.com>"' > $tmpMapFile && chmod +x $tmpMapFile && echo $tmpMapFile) https://svn.example.com/svn/repo/

This will force all mappings are exacly the same and SVN clones might be "shared" and merged via git!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM