git-svn Tips

1
$ git svn clone http://svn.example.com/project [-T trunk] [-b branches] [-t tags]
1
$ git svn rebase
1
$ git svn dcommit

假设我们要checkout的支线叫"another-branch",首先在.git/config添加:

1
2
3
[svn-remote "another-branch"]
    url = http://svn.example.com/project/branches/another-branch
    fetch = :refs/remotes/another-branch

然后在命令行里执行:

1
2
$ git svn fetch another-branch
$ git checkout -b another-branch remotes/another-branch
1
$ git svn fetch --fetch-all

我一开始想复杂了,写了下面的脚本,先在原来的支线上生成某一提交的patch,然后到另一支线打上该patch:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [ $1 == "-h" ]; then
    echo "Usage: "
    echo "$(basename $0) <git commit SHA1>"
    exit 0
fi

SHA1=$1

REPO_DIR=""
PATCH_DIR=""

SOURCE_BRANCH=master
DEST_BRANCH=dev

# cd ${REPO_DIR}
git stash
git checkout ${SOURCE_BRANCH}

patch_file=`git format-patch -1 ${SHA1} -o ${PATCH_DIR}`

git checkout ${DEST_BRANCH}
git svn rebase

# Apply patch for any svn repo:
# patch -p1 -i ${patch_file}
# In a git-svn repo, use `git am` instead:
git am ${patch_file}

# Check the commit manually
# tig

git svn dcommit

git checkout ${SOURCE_BRANCH}
git stash pop

后来发现git-svncheckout的svn支线其实和git支线没什么两样,用git cherry-pick就可以了。

1
$ git svn show-ignore >> .git/info/exclude

References

Adding a Branch to Git

Add an SVN remote to your Git repo

Add svn repo to existing git repo?

Checkout remote branch using git svn

Selective import of SVN branches into a git/git-svn repository