目前,当我运行git svn dcommit
时,git会为我自上次与SVN同步以来所做的每个本地提交在SVN中创建一个单独的提交。有没有办法让dcommit
将我最近的所有本地提交合并为一个提交以供SVN使用?
git rebase remotes/trunk --interactive
应该会把你带到菜单上,你可以在其中选择提交(commit)或将它们全部压缩成一个提交(commit),以避免污染你的svn仓库。 这个 是一个关于如何使用git-svn的真的不错(但很短)的资源。
trunk
分支对应的master
分支上,并且想要将所有本地提交压缩在一起:git tag local # create a temporary tag
git reset --hard trunk
git merge --squash local
git commit # write your single commit message here
git svn dcommit
git tag -d local # delete the temporary tag named local
你可以使用 reflog(即使用 master@{1}
替换 local
)而不是使用临时标签。
git svn rebase && git push . remotes/trunk:master
git checkout master
git merge <branch> --no-ff -m "Message you want in svn"
git svn dcommit
+--- Merge commit
V
svn trunk *---*---*-------------------*--- --- ---
\ /
topic branch *---*---*---*---*
git reset <hash tag of commit till which u need to combine>
git commit -am "your message" // This will create one clubbed commit of all the commit till the hash tag used.
这对我很有用 - 把几个提交压缩成一个提交,然后dcommit到svn:
http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
这对我不起作用。我使用merge --no-ff --no-commit
,但提交后,我得到了:
svntrunk 54f35e4 [trunk: ahead 336] release 1
提交到主干 trunk 将会提交所有的336个commit。
重置、标记和压缩,就像回答#2中描述的那样:将本地Git提交合并为一个git-svn提交,这样做是可以的,但在下一次"合并"时,你可能会遇到一些困难,无法再次获得所有的提交!
对我来说,唯一有效的方法是:
git checkout -tb svntrunk remotes/trunk
git merge --no-commit --squash master
为了在未来使用相同的命令进行合并而不丢失历史记录,从主分支到svn获取所有提交
~ Marcel