将本地 Git 提交合并为 git-svn 的一次提交

发布于 2024-08-04 00:28:49 字数 132 浏览 6 评论 0原文

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

Currently, when I run git svn dcommit git creates a separate commit in SVN for every local commit I've made since last syncing with SVN. Is there any way for dcommit to instead combine all my recent local commits into one commit for SVN?

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

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

发布评论

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

评论(6

清旖 2024-08-11 00:28:49
git rebase remotes/trunk --interactive 

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

git rebase remotes/trunk --interactive 

should bring you to the menu where you can pick commits or squash them all into 1 commit in order to avoid polluting your svn repository. This is a really good (but short) resource on working with git-svn.

羅雙樹 2024-08-11 00:28:49

不,但是您可以轻松地将所有提交压缩在一起。对于以下示例,我假设您位于与远程 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

:使用临时标记时,您也可以只使用引用日志(即使用 master@{1} 代替 local

No, but you can squish all the commits together pretty easily. For the following example, I'm going to assume you're on the master branch corresponding to the remote trunk branch and that you want to squish all local commits together:

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

Instead of using a temporary tag you could also just use the reflog (i.e. use master@{1} in place of local)

烦人精 2024-08-11 00:28:49

当我使用 git-svn 并希望一系列 git 提交显示为单个提交时,我会处理一个主题分支,然后在 之前执行非快进 合并 到 master 中>dcommit-ing。

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

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

然后切换到 master,合并并提交:

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         *---*---*---*---*

When I work with git-svn and want a series of git commits to show up as a single commit, I work on a topic branch and then do a non-fast-forward merge into master before dcommit-ing.

First, rebase your branch against svn and make sure local master is up-to-date:

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

Then switch to master, merge and dcommit:

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

This will show up as a single commit in Subversion but you will still have your local history that got you to that commit.

                                       +--- Merge commit
                                       V
svn trunk  *---*---*-------------------*--- --- ---
                    \                 /
topic branch         *---*---*---*---*
谁许谁一生繁华 2024-08-11 00:28:49

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

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.

A simpler way could be (if you have multiple commits piled up on your local system):

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.
甜中书 2024-08-11 00:28:49

这对我有用——将多个提交压缩为一个提交,然后提交到 svn:

This worked for me--squashed several commits into one commit and then dcommitted to svn:

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

坦然微笑 2024-08-11 00:28:49

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

svntrunk                        54f35e4 [trunk: ahead 336] release 1

dcommitting to trunkwill commit all 336 commits。

如答案#2中所述重置、标记和压缩: 将本地 Git 提交合并为 git-svn 的一个提交 可以,但是在下一次“合并”时,您将遇到一些麻烦,无法再次将所有提交合并在一起!

唯一对我有用的方法:

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

从 master 到 svn 的所有提交都不会丢失历史记录,以便将来使用相同的命令合并

~Marcel

that is not working for me. I use merge --no-ff --no-commit but after commit, I got:

svntrunk                        54f35e4 [trunk: ahead 336] release 1

dcommitting to trunkwill commit all 336 commits.

resetting, tagging, and squashing as described in answer #2: Combine local Git commits into one commit for git-svn will work, but on next "merge" you will have some trouble to get all commits together again!

the one and only that is working for me:

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

to get all commits from master to svn without loosing history for future merging with the same command

~Marcel

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