是否可以使 git svn dcommit 导致单个 svn 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/158514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:04:29  来源:igfitidea点击:

Is it possible to make git svn dcommit result in a single svn commit?

svngitgit-svn

提问by plindberg

According to the manual, git dcommit“will create a revision in SVN for each commit in git.” But is there a way to avoid multiple Subversion revisions? That is, to have git merge all changes prior to performing the svn commit?

根据手册git dcommit“将在 SVN 中为 git 中的每个提交创建一个修订版。” 但是有没有办法避免多次 Subversion 修订?也就是说,在执行svn commit?

采纳答案by davetron5000

If you work on a branch in git, you can git-merge --squash, which does that within git. You could then push that one squashed commit to SVN.

如果你在 git 的一个分支上工作,你可以git-merge --squash,它在 git 中完成。然后,您可以将压扁的提交推送到 SVN。

Of course, lots of small commits are good, so why would you want to squash them?

当然,很多小的提交都是好的,那你为什么要压缩它们呢?

回答by andy

The command git rebase -ican do this, and more. This command is extremely powerful, so it's good to make friends with it.

命令git rebase -i可以做到这一点,等等。这个命令非常强大,所以用它来交朋友是很好的。

The syntax is: git rebase -i <commit ID>. This brings up your text editor, with options (and instructions) for modifying all the commits up to (not including) the given ID.

语法是:git rebase -i <commit ID>. 这将打开您的文本编辑器,其中包含用于修改所有提交(不包括)给定 ID 之前的选项(和说明)。

For example, to modify the previous 5 commits, you can do this:

例如,要修改前 5 次提交,您可以这样做:

git rebase -i HEAD~5

git rebase -i HEAD~5

Or if your SVN branch is called "svn/trunk", then this syntax is good too:

或者如果你的 SVN 分支被称为“svn/trunk”,那么这个语法也很好:

git rebase -i svn/trunk

git rebase -i svn/trunk

Then a text editor window will pop up. To squash everything, change the first word of every line after the first from "pick" to "squash" (If this sounds confusing- it will make more sense when you see it). Then save and close the editor. You'll then have a chance to edit the commit message for the squashed commit.

然后会弹出一个文本编辑器窗口。要压缩所有内容,请将第一行之后的每一行的第一个单词从“pick”更改为“squash”(如果这听起来令人困惑-当您看到它时会更有意义)。然后保存并关闭编辑器。然后,您将有机会编辑压缩提交的提交消息。

Among the other things you can do with git rebase -i, are reordering commits, squashing commits in different ways, and removing commits.

您可以使用 做的其他事情git rebase -i包括重新排序提交、以不同方式压缩提交以及删除提交。

I use this command constantly; it's a killer feature of Git.

我经常使用这个命令;这是 Git 的一个杀手级功能。

回答by cbowns

Ryan Tomaykowrote a bit about git rebase -i, which he said:

Ryan Tomayko写了一些关于git rebase -i,他说:

…[it's] a bit like git commit --amend hopped up on acid and holding a chainsaw – completely insane and quite dangerous but capable of exposing entirely new states of mind. Here you can edit, squash, reorder, tease apart, and annotate existing commits in a way that's easier and more intuitive than it ought to be.

... [它] 有点像 git commit --amend 跳上酸液并拿着电锯 - 完全疯了,相当危险,但能够暴露出全新的心态。在这里,您可以以比应有的方式更简单、更直观的方式编辑、压缩、重新排序、梳理和注释现有提交。

I have a tendency to commit often in git, but don't necessarily want to dcommit everycommit to svn, and squashing all my work makes just as little sense. I'm trying it now to reorder and squash a few together into more logical commit units now.

我有经常在 git 中提交的倾向,但不一定要 dcommit对 svn 的每次提交,并且压缩我所有的工作也没有什么意义。我现在正在尝试将一些重新排序并压缩到更合乎逻辑的提交单元中。