简体   繁体   English

是否有可能在单个svn提交中使git svn dcommit结果?

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

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? 根据手册git dcommit “将在git中为每个提交创建一个SVN版本。”但是有没有办法避免多个Subversion修订? That is, to have git merge all changes prior to performing the svn commit ? 也就是说,让git在执行svn commit之前合并所有更改?

If you work on a branch in git, you can git-merge --squash , which does that within git. 如果你在git中的一个分支上工作,你可以git-merge --squash ,它在git中完成。 You could then push that one squashed commit to SVN. 然后你可以将那个压扁的提交推送到SVN。

Of course, lots of small commits are good, so why would you want to squash them? 当然,很多小提交都很好,那你为什么要挤压它们呢?

The command git rebase -i can do this, and more. 命令git rebase -i可以执行此操作,等等。 This command is extremely powerful, so it's good to make friends with it. 这个命令非常强大,所以与它交朋友是件好事。

The syntax is: git rebase -i <commit ID> . 语法为: 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. 这将打开文本编辑器,其中包含用于修改所有提交(不包括)给定ID的选项(和说明)。

For example, to modify the previous 5 commits, you can do this: 例如,要修改之前的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

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). 要压扁所有东西,将第一个单词后面的第一个单词从“pick”更改为“squash”(如果这看起来很混乱 - 当你看到它时会更有意义)。 Then save and close the editor. 然后保存并关闭编辑器。 You'll then have a chance to edit the commit message for the squashed commit. 然后,您将有机会编辑压缩提交的提交消息。

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的杀手级功能。

Ryan Tomayko wrote 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. ...... [它]有点像git commit -amend跳上酸和拿着电锯 - 完全疯了,非常危险但能够暴露出全新的心态。 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. 在这里,您可以以比它应该更容易和更直观的方式编辑,压缩,重新排序,分离和注释现有提交。

I have a tendency to commit often in git, but don't necessarily want to dcommit every commit to svn, and squashing all my work makes just as little sense. 我倾向于经常在git中提交,但不一定要将每个提交提交给svn,并且压缩我所有的工作也没什么意义。 I'm trying it now to reorder and squash a few together into more logical commit units now. 我现在正在尝试重新排序并将一些压缩成更多逻辑提交单元。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM