如何通过使用唯一的Git合并在一个Git分支到SVN的“树干”的变化

时间:2019-02-02 18:54:11

标签: git svn version-control

我想签出SVN项目,在远程SVN和相应的本地Git分支上创建一个分支。然后,我想要做一些改变。的变化应该反映在两个分支 - SVN和GIT中的一些人在SVN工作,他们应该看到分支task3

以下脚本成功完成了

#!/bin/bash
DIR=/tmp/svn-experiments # Directory for experiments
rm -rf "$DIR"
mkdir "$DIR"

cd $DIR
rm -rf svnrepos
svnadmin create svnrepos

# Create a project with standard SVN-project folder structure:
mkdir -p project/{trunk,branches,tags}
cd project/trunk/
echo "Hello" > readme.txt
echo "Log entry 1" > day.log

# Import the project into repository
svn import -m "Project import into repository" "$DIR"/project file://"$DIR"/svnrepos/project

svn log file://"$DIR"/svnrepos/project

# Simulate two users and conflict

# Developer 1 (svn) creates working copy, branch:
svn co file://"$DIR"/svnrepos/project "$DIR"/developer_svn1

cd "$DIR"/developer_svn1

svn copy file://"$DIR"/svnrepos/project/trunk file://"$DIR"/svnrepos/project/branches/task1 -m "Create a branch for task 1" 

svn update

cd "$DIR"/developer_svn1/branches/task1

sed -i -r 's/(.*)/\1 world/g' readme.txt

svn commit -m "Change from developer_svn1"

svn update

# Developer 2 (svn) creates working copy, branch:
svn co file://"$DIR"/svnrepos/project "$DIR"/developer_svn2

cd "$DIR"/developer_svn2

svn copy file://"$DIR"/svnrepos/project/trunk file://"$DIR"/svnrepos/project/branches/task2 -m "Create a branch for task 2" 

svn update

cd "$DIR"/developer_svn2/branches/task2

sed -i -r 's/(.*)/\1 Russia/g' readme.txt

svn commit -m "Change from developer_svn2"

svn update

# Currently creates a remote SVN branch 'task3' and the corresponding local Git branch 'task3'
# Commits to local and remote
# TODO How to merge changes in 'task3' into 'trunk' of SVN by using Git only?
git-workflow() {
# Developer 3 (git) creates working copy, branch:
git svn clone -s file://"$DIR"/svnrepos/project "$DIR"/developer_git1

cd "$DIR"/developer_git1

git svn -m "Create a branch for task 3" branch task3 # The branch will be created on SVN

git branch task3 remotes/origin/task3 

git checkout task3

sed -i -r 's/(.*)/\1 Germany/g' readme.txt

git add -u

git commit -m "Change from developer_git1" # Commit in local Git branch

git svn dcommit # Commit to the corresponding SVN branch

}

但是我不知道如何将本地Git分支task3中的更改合并到SVN的trunk中。

我尝试了以下操作:

/tmp/svn-experiments/developer_git1$ git branch -a
  master
* task3
  remotes/origin/task1
  remotes/origin/task2
  remotes/origin/task3
  remotes/origin/trunk
/tmp/svn-experiments/developer_git1$ git checkout master
Switched to branch 'master'
/tmp/svn-experiments/developer_git1$ git show-ref
7c4844a091dd649a7ffd15a3dac07da927fca426 refs/heads/master
2e0964804ba1f3f84baaba8ade0934899ea2a69d refs/heads/task3
6e42f27d10ca25a0189b94d8dc1ada96a38f494b refs/remotes/origin/task1
7992320699f10f77062c2c7fa9c78edeec2ce01b refs/remotes/origin/task2
2e0964804ba1f3f84baaba8ade0934899ea2a69d refs/remotes/origin/task3
7c4844a091dd649a7ffd15a3dac07da927fca426 refs/remotes/origin/trunk
/tmp/svn-experiments/developer_git1$ git merge task3 
Updating 7c4844a..2e09648
Fast-forward
 readme.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
/tmp/svn-experiments/developer_git1$ git show-ref
2e0964804ba1f3f84baaba8ade0934899ea2a69d refs/heads/master
2e0964804ba1f3f84baaba8ade0934899ea2a69d refs/heads/task3
6e42f27d10ca25a0189b94d8dc1ada96a38f494b refs/remotes/origin/task1
7992320699f10f77062c2c7fa9c78edeec2ce01b refs/remotes/origin/task2
2e0964804ba1f3f84baaba8ade0934899ea2a69d refs/remotes/origin/task3
7c4844a091dd649a7ffd15a3dac07da927fca426 refs/remotes/origin/trunk
/tmp/svn-experiments/developer_git1$ git svn dcommit
Committing to file:///tmp/svn-experiments/svnrepos/project/branches/task3 ...

我如何强迫master指向trunk并在那里提交?

1 个答案:

答案 0 :(得分:0)

我从未见过有人使用git推送到SVN的情况。如果您正在使用SVN工作流程,则应使用tortoiseSVN而不是git。参见https://tortoisesvn.net/