28

目前,当我运行git svn dcommitgit 时,我会在 SVN 中为我上次与 SVN 同步后所做的每个本地提交创建一个单独的提交。有什么办法可以dcommit将我最近的所有本地提交合并为一个 SVN 提交?

4

6 回答 6

18
git rebase remotes/trunk --interactive 

应该将您带到菜单,您可以在其中选择提交或将它们全部压缩为 1 个提交,以避免污染您的 svn 存储库。 是使用 git-svn 的一个非常好的(但很短)的资源。

于 2009-09-11T00:18:33.117 回答
17

不,但是您可以很容易地将所有提交压缩在一起。对于以下示例,我将假设您位于master与远程分支对应的分支上trunk,并且您希望将所有本地提交压缩在一起:

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

于 2009-09-11T00:18:45.737 回答
3

当我使用 git-svn 并希望一系列 git 提交显示为单个提交时,我在主题分支上工作,然后在-ingmerge之前执行非快进到 master 。dcommit

首先,根据 svn 重新设置您的分支并确保本地 master 是最新的:

git svn rebase && git push . remotes/trunk:master

然后切换到master,merge和dcommit:

git checkout master
git merge <branch> --no-ff -m "Message you want in svn"
git svn dcommit

这将在 Subversion 中显示为单个提交,但您仍将拥有使您进行该提交的本地历史记录。

                                       +--- Merge commit
                                       V
svn trunk  *---*---*-------------------*--- --- ---
                    \                 /
topic branch         *---*---*---*---*
于 2010-11-05T00:21:12.740 回答
3

一种更简单的方法可能是(如果您在本地系统上堆积了多个提交):

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.
于 2011-05-26T06:34:11.067 回答
2

这对我有用——将几个提交压缩成一个提交,然后 dcommitted 到 svn:

http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

于 2010-11-05T00:00:05.237 回答
0

这对我不起作用。我使用merge --no-ff --no-commit但在提交后,我得到了:

svntrunk                        54f35e4 [trunk: ahead 336] release 1

dcommitting to trunk 将提交所有 336 次提交。

如答案 #2 中所述重置、标记和压缩:将本地 Git 提交合并到一个提交中以使 git-svn可以工作,但是在下一次“合并”时,您将很难再次将所有提交放在一起!

唯一对我有用的:

git checkout -tb svntrunk remotes/trunk
git merge --no-commit --squash master

获取从 master 到 svn 的所有提交,而不会丢失历史以供将来使用相同的命令合并

〜马塞尔

于 2011-07-13T08:22:08.590 回答