简体   繁体   English

Git 和 SVN 通过 git svn 分支合并。 哪种程序最好?

[英]Git and SVN via git svn branch merging. Which procedure is the best?

I'am using git svn to sync sources between git and SVN.我正在使用 git svn 在 git 和 SVN 之间同步源。 I like to work with branches and that's the problem.我喜欢与分支机构合作,这就是问题所在。

I'm creating a branch with: git svn branch mybranch我正在创建一个分支: git svn branch mybranch

After that i check the branch out.之后我检查分支。 After i modified the sources i'm ready to merge mybranch to the master branch.在我修改了源代码后,我准备将 mybranch 合并到 master 分支。

How are you doing it?你怎么样? git merge does not work and git merge --no-ff creates a single commit. git 合并不起作用, git merge --no-ff 创建单个提交。 Are you using cherry-pick to pick those commits?您是否使用cherry-pick 来挑选那些提交? How you integrate your changes from mybranch to master without losing the commits you created in mybranch?如何在不丢失在 mybranch 中创建的提交的情况下将更改从 mybranch 集成到 master?

Thank you very much!非常感谢!

Branching and merging in SVN is significantly different from branching and merging in Git. SVN 中的分支和合并与 Git 中的分支和合并显着不同。 Git's is far superior. Git的要好得多。 SVN cannot handle most of the merges git does. SVN 无法处理 git 所做的大部分合并。 Here is how I would recommend merging be done:以下是我建议的合并方式:

case 1) Creating a personal feature branch then merge it back into a shared SVN branch案例 1) 创建个人功能分支,然后将其合并回共享的 SVN 分支

In this case, create the feature branch only in Git.在这种情况下,仅在 Git 中创建特征分支。 Commit as necessary in git.根据需要在 git 中提交。 Feel free to rebase/squash as often as necessary.如有必要,请随时进行 rebase/squash。 When you are ready to merge your changes back into the SVN shared branch:当您准备好将更改合并回 SVN 共享分支时:

case 1a) You want all your separate commits to be stored in SVN案例 1a)您希望将所有单独的提交存储在 SVN

Rebase your feature branch so that all its commits come after the tip of the shared branch.重新设置您的功能分支,使其所有提交都在共享分支的尖端之后。 Then fast-forward merge your feature branch into the shared branch.然后快进将您的功能分支合并到共享分支中。 This leaves a linear history in your SVN shared branch.这会在您的 SVN 共享分支中留下线性历史记录。 This is important.这个很重要。 SVN cannot handle non-linear histories. SVN 无法处理非线性历史。 Now you can push your shared branch to SVN (be sure to update from SVN first).现在您可以将您的共享分支推送到 SVN(请务必先从 SVN 更新)。

git checkout myfeature
git rebase master    # we need a linear history on master, so rebase
git checkout master
git merge myfeature --ff-only  # ff-only ensures a linear history
git svn rebase  #update from SVN
git svn dcommit #finally, commit to SVN

case 1b) You only want a single commit in your SVN history.案例 1b)您只需要在 SVN 历史记录中进行一次提交。

In this case, do a merge --squash.在这种情况下,请执行合并 --squash。 This will add a single commit to your shared branch which you can push to SVN.这将向您的共享分支添加一个提交,您可以将其推送到 SVN。 Your feature branch should be deleted (or replaced with a tag if you want to keep your separate commits in git history) as git will have no history of the merge, and future merges made from the branch can cause unnecessary conflicts.您的功能分支应该被删除(如果您想在 git 历史记录中保留您的单独提交,则应将其替换为标签),因为 git 将没有合并历史记录,并且将来从分支进行的合并可能会导致不必要的冲突。

case 2) You need to merge two SVN branches.案例 2)您需要合并两个 SVN 分支。

ALWAYS merge SVN branches in SVN, and not Git.总是在 SVN 中合并 SVN 分支,而不是 Git。 SVN cannot handle Git merges, If you merge in Git. SVN 无法处理 Git 合并,如果在 Git 中合并。 SVN will not be able to merge those branches without problems in the future. SVN 将来将无法毫无问题地合并这些分支。 Git should still be able to detect a merge if SVN did it.如果 SVN 做到了,Git 应该仍然能够检测到合并。

Alternately, you can do all merges in Git.或者,您可以在 Git 中进行所有合并。 Since SVN will not know anything about these merges (it will not know that the commits are merge commits) SVN will not be able to merge those branches without a lot of manual intervention.由于 SVN 对这些合并一无所知(它不会知道提交是合并提交) SVN 将无法在没有大量手动干预的情况下合并这些分支。 SVN uses "mergeinfo" to keep track of which commits have already been applied to which branches, and merging in Git will not update SVN's mergeinfo. SVN 使用“mergeinfo”来跟踪哪些提交已经应用于哪些分支,并且在 Git 中合并不会更新 SVN 的 mergeinfo。 So your choice is always merge SVN branches in SVN, or always in Git.所以你的选择是总是在 SVN 中合并 SVN 分支,或者总是在 Git 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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