git-svn 在多个远程之间合并

发布于 2024-11-17 19:31:18 字数 956 浏览 1 评论 0原文

我有 git-svn 设置来跟踪两个远程 svn 位置,例如 http://svnserver/develop/project 和 < a href="http://svnserver/release/project" rel="nofollow">http://svnserver/release/project 。

我还创建了遥控器的本地分支,以便进行更改并提交它们。但是,当我尝试将更改从开发的本地分支合并到发布的本地分支时,我遇到了需要在文本编辑器中解决的冲突。

工作流程示例

# Setup the repos
git svn init http://svnserver/develop/project -R develop -i svn-develop
git svn init http://svnserver/release/project -R release -i svn-release
git svn fetch develop
git svn fetch release
git checkout svn-release
git checkout -b release
git checkout svn-develop
git checkout -b develop

# Make changes to develop branch and commit to svn
git commit -a -m "Changes"
git svn dcommit

# I'd like to bring changes to release branch
git checkout release
git merge develop --squash

# Ack! Conflicts :<

为什么 git 不能简单地将 diff 应用于发布分支?我的遥控器设置不正确吗?是因为他们没有被单亲追踪吗?

感谢您的帮助!

I have git-svn setup to track two remote svn locations, say http://svnserver/develop/project and http://svnserver/release/project .

I also created local branches of the remotes in order to make changes and dcommit to them. However, when I try to merge a change from a local branch of develop to a local branch of release, I get conflicts which needs to be resolved in a text editor.

Example workflow

# Setup the repos
git svn init http://svnserver/develop/project -R develop -i svn-develop
git svn init http://svnserver/release/project -R release -i svn-release
git svn fetch develop
git svn fetch release
git checkout svn-release
git checkout -b release
git checkout svn-develop
git checkout -b develop

# Make changes to develop branch and commit to svn
git commit -a -m "Changes"
git svn dcommit

# I'd like to bring changes to release branch
git checkout release
git merge develop --squash

# Ack! Conflicts :<

Why can't git simply apply the diff to the release branch? Did I setup my remotes incorrectly? Is it because they are not tracked from a single parent?

Appreciate the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-11-24 19:31:18

简短的回答是,不,你不能这样做。

一点细节:

您最初的合并问题是因为 svn-release 和 svn-develop 不共享父提交,并且 git 的自动合并工具根本无法工作。您必须手动合并并创建一个它们作为父级共享的提交。

问题还不止于此。 Subversion 在管理提交方面是线性的,您会注意到,当您执行 git svn dcommit 时,推送的本地提交在进入 subversion 后实际上会被重写,以反映svn 修订号。这会更改提交的本地 git sha1sum,这本质上是对历史记录的重写。如果您有其他要合并的本地 git 分支,则重写历史记录会导致各种问题,并且将来会继续遇到合并问题。

基本上,如果您进行初始合并提交,进行更多开发,并将这些更改推送回来,您的合并提交将被重写,它的 sha1sum 已更改,并且您的分支将不再共享父级。每次你想要合并/推送时,你都会再次从同样的问题开始。

The short answer is, no, you can't do this.

A bit of detail:

Your initial merge problem is because svn-release and svn-develop don't share a parent commit, and git's automatic merging tools simply won't work. You'd have to merge manually and create a commit that they both share as a parent.

The problems don't stop there. Subversion is liner in how it manages commits, and you'll notice that when you do the git svn dcommit, your local commits that get pushed are actually re-written after they go into subversion, to reflect the svn revision number. This changes the local git sha1sum of the commit, which is essentially a re-write of history. Re-writing history causes all sorts of issues if you have other local git branches that you merge with, and will continue to run into merging problems down the road.

Basically, if you do your initial merge commit, do more development, and push those changes back up, your merge commit will get re-written, it's sha1sum changed, and your branches will no longer share a parent. You'd starting with the same problem over again each time you want to merge/push.

固执像三岁 2024-11-24 19:31:18

更长的答案:是的,你可以这样做,但不是微不足道的。

我所处的情况是,我有两个独立的 SVN 存储库,之前由 Bazaar 管理。它们共享共同的历史记录(由 Bazaar 从一个存储库推送到另一个存储库),但具有完全不同的提交 ID,因为它们位于不同的存储库中,并且 git-svn 将存储库 ID 滚动到提交消息中,这会影响 SHA1。

它们的共同点是它们的根树 ID 在它们分歧之前都是相同的 - 对于相同的树,树对象的 SHA1 将是相同的。

所以我的计划是:

  • 退役一个或两个 SVN 存储库(我真的不想再这样做)
  • 将所有修订迁移到同一个 Git 存储库

    1. 将两棵树克隆到不同的 Git 存储库
    2. 列出所有根树 ID 并比较它们以找到它们的分歧点。
    3. 此时在我的目标存储库中创建一个分支
    4. 对于我的源存储库中的每个后续修订
      • 在源存储库中查看它
      • 用此树替换目标存储库中的树
      • 提交该修订

我最终应该得到一个包含两个具有正确起点的分歧分支的 Git 存储库。到那时,合并有望变得容易得多。

A longer answer : yes, you can do this, but not trivially.

The circumstance I'm in is that I have two separate SVN repositories that were previously managed with Bazaar. They share a common history (pushed from one repo to the other by Bazaar), but have totally different commit IDs because they were in different repositories, and git-svn rolls repo ID into the commit message, which affects the SHA1.

What they will have in common is that their root tree IDs will be the same up to the point at which they diverge - the SHA1 of the tree object will be identical for identical trees.

So my plan is to :

  • Retire one or both SVN repositories (I really don't want have to do this again)
  • Migrate all revisions into the same Git repository

    1. Clone both trees into different Git repositories
    2. List all the root tree IDs and compare them to find the point at which they diverge.
    3. Create a branch in my target repository at this point
    4. For each subsequent revision in my source repository
      • Check it out in the source repository
      • Replace the tree in the target repository with this tree
      • Commit that revision

I should end up with a single Git repository containing both diverging branches with the correct point of origin. At which point, merging is hopefully a lot easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文