git-svn:如何将git提交从一个SVN分支复制到另一个分支? [英] git-svn: how to copy git commits from one SVN branch to another?

查看:386
本文介绍了git-svn:如何将git提交从一个SVN分支复制到另一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的git-svn签出了我的整个回购(在标准 git svn init -t tags -b分支-T trunk $ repo_url 时尚中初始化)然后 git svn fetch ed)。我手动 svn copy $ repo_url / branches / branch1 $ repo_url / branches / branch2 。然后我运行了 git svn fetch git checkout -b local-branch2 branch2 ,做了一些提交到 branch2 dcommit 将它们重新编译回SVN仓库,并且在 branch2 code>。 (为什么要分支一个分支?我想在git中本地攻击这个分支,但是仍然在SVN中提交并在一些同事的帮助下从我的工作中获得帮助)。



我没有做的是将 branch2 工作合并回到 branch1 中。如果我 git checkout -b local-branch1 branch1 ,那么 git merge branch2 ,它只是快进我的 local-branch1 指向其中 branch2 的指针。



我希望git将自从 branch2 开始的所有提交重放到branch1上,以便我可以将它们中的每一个提交到SVN repo。似乎有办法做到这一点,但我想不起来。可能 git rebase ,或者 branch2 中每个提交的 git cherry-pick code>? (尽管后者有点乏味)。我宁愿不svn合并这两个网址,因为这是一大桶伤害。

想法?任何部分都需要更多的解释吗?

解决方案

branch2上的第一次提交不在local-branch1上可能是创建的提交分支2,是吗?这应该显示为git中的空提交(例如,消息,但不包含内容)。复制它的sha1标识符。然后在local-branch1中,尝试 git reset --hard branch2&& git rebase --onto local-branch1 @ {1} SHA1 (其中SHA1是复制的sha1)。这应该会重播所有的提交,除了空的一个回到分支1上。你很可能现在想要做一个交互式重新分配和编辑每个提交,这样你就可以去掉git-svn-id:这行git-svn为你添加的(或者你可以写一个git-filter-branch脚本来做,如果有足够的提交)。



出于好奇,为什么你要重播每一个承诺?如果你想简单地合并你的修改,那就简单多了,你可以做 git checkout local-branch1&& git merge --squash branch2&& git commit 。这会做非快进合并,但实际上并不会产生合并提交(因为那些混淆了git-svn)。相反,它会产生等效的工作树,就像合并发生一样,但只有一个父亲。这反映了svn如何合并工作。


I've got a git-svn checkout of my entire repo (initialized in the standard git svn init -t tags -b branches -T trunk $repo_url fashion, then git svn fetched). I manually svn copy $repo_url/branches/branch1 $repo_url/branches/branch2. I then ran git svn fetch, git checkout -b local-branch2 branch2, made a few commits to branch2, dcommited them back to the SVN repo, and am done with my work on branch2. (Why branch a branch? I wanted to hack at this branch locally in git, but still commit back to SVN and get help from a couple of coworkers while I was working on it).

What I haven't done is merge the branch2 work back into branch1. If I git checkout -b local-branch1 branch1, then git merge branch2, it simply fast-forwards my local-branch1 pointer to where branch2 is.

Instead, I want git to replay all commits made since starting branch2 onto branch1, so that I can dcommit each of them to the SVN repo. It seems like there's a way to do this, but I can't think of it. Maybe git rebase, or a git cherry-pick of each commit made on branch2? (though the latter is a bit tedious). I'd rather not svn merge the two URLs together, as that's a big bucket of hurt.

Ideas? Any parts of this need more explanation?

解决方案

The first commit on branch2 that's not on local-branch1 is presumably the commit that created branch2, yes? This should appear as an empty commit in git (e.g. a message, but no contents). Copy its sha1 identifier. Then in local-branch1, try git reset --hard branch2 && git rebase --onto local-branch1@{1} SHA1 (where SHA1 is the copied sha1). This should replay all the commits except that empty one back onto branch 1. You will most likely now want to do an interactive rebase and edit each commit so you can strip out the git-svn-id: line that git-svn adds for you (or you could write a git-filter-branch script to do so, if there's enough commits).

Out of curiosity, why do you want to replay each of the commits? If you want to simply merge your changes in, it's much simpler, you can just do git checkout local-branch1 && git merge --squash branch2 && git commit. This will do a non-fast-forward merge, but it won't actually produce a merge commit (as those confuse git-svn). Instead it will produce the equivalent working tree as if a merge had happened, but with only a single parent. This mirrors how svn merges work.

这篇关于git-svn:如何将git提交从一个SVN分支复制到另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆