git Subversion 的部分提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/75809/
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
Partial Commits with Subversion
提问by Benedikt Waldvogel
Given the case I made two independent changesin onefile: eg. added a new method and changed another method.
鉴于这种情况,我在一个文件中进行了两次独立的更改:例如。添加了一个新方法并更改了另一个方法。
I often don't want to commit both changes as onecommit, but as twoindependent commits.
我通常不想将两个更改作为一次提交提交,而是作为两个独立的提交提交。
On a git repository I would use the Interactive Modeof git-add(1)to split the hunkinto smaller ones:
在一个Git仓库我会使用交互模式的混帐加(1)到拆分大块分成较小的:
git add --patch
What's the easiest way to do this with Subversion? (Maybe even using an Eclipse plug-in)
使用 Subversion 执行此操作的最简单方法是什么?(甚至可能使用 Eclipse 插件)
Update:
In The Thing About Git, Ryan calls it: “The Tangled Working Copy Problem.”
更新:
在The Thing About Git 中,Ryan 称其为:“纠结的工作副本问题”。
采纳答案by jkramer
With git-svn you can make a local GIT repository of the remote SVN repository, work with it using the full GIT feature set (including partial commits) and then push it all back to the SVN repository.
使用 git-svn,您可以创建远程 SVN 存储库的本地 GIT 存储库,使用完整的 GIT 功能集(包括部分提交)使用它,然后将其全部推送回 SVN 存储库。
回答by Casebash
Tortoise SVN 1.8 now supportsthis with it's "Restore after commit" feature. This allow you to make edits to a file, with all of the edits being undone after the commit
Tortoise SVN 1.8现在通过它的“提交后恢复”功能支持这一点。这允许您对文件进行编辑,并在提交后撤消所有编辑
Per the documentation:
根据文档:
To commit only the parts of the file that relate to one specific issue:
- in the commit dialog, right-click on file, choose "restore after commit"
- edit the file in e.g. TortoiseMerge: undo the changes that you don't want to commit yet
- save the file
- commit the file
仅提交与一个特定问题相关的文件部分:
- 在提交对话框中,右键单击文件,选择“提交后恢复”
- 在例如 TortoiseMerge 中编辑文件:撤消您还不想提交的更改
- 保存文件
- 提交文件
回答by Spike
I have done this using TortoiseSVN.
我已经使用TortoiseSVN做到了这一点。
The built in merge utility allows you to show a diff between the repository version and your working copy.
内置的合并实用程序允许您显示存储库版本和工作副本之间的差异。
Use the create backupfunction of the diff utility
使用diff 实用程序的创建备份功能
- Go to commit your file as if you were going to commit all your changes.
- In the commit window, double click the file to show a diff.
- In the diff settings, click the option to backup original file.
- Right-click the changes you don't want, and use select use other text block.
- Save the diff exactly once. The backup will be overwritten each time you save. This is why you only want to save once.
- Commit the change.
- Overwrite the original with the created .bak file (which will have all your original changes).
- Commit your file.
- 去提交您的文件,就像您要提交所有更改一样。
- 在提交窗口中,双击文件以显示差异。
- 在差异设置中,单击备份原始文件的选项。
- 右键单击您不想要的更改,然后使用 select use other text block。
- 将差异保存一次。每次保存时都会覆盖备份。这就是为什么您只想保存一次。
- 提交更改。
- 用创建的 .bak 文件覆盖原始文件(它将包含您所有的原始更改)。
- 提交您的文件。
You should now have all your changes committed, using two separate commits.
您现在应该使用两个单独的提交提交所有更改。
回答by Chris
Try using svn diff > out.patch
then copy the out.patch
file to out.patch.add
and out.patch.modify
尝试使用svn diff > out.patch
然后将out.patch
文件复制到out.patch.add
和out.patch.modify
Only when you have a working patch filerevert the original file using svn revert out.c
.
仅当您有可用的补丁文件时,才使用svn revert out.c
.
Edit the patch files by hand so that they only contain the hunksfor adding or modifying. Apply them to the original file using the patch
command, test if the addition worked, then svn commit
the addition.
手动编辑补丁文件,使它们只包含用于添加或修改的大块。使用patch
命令将它们应用到原始文件,测试添加是否有效,然后svn commit
添加。
Wash rinse repeat for the out.patch.modify
patch.
清洗冲洗重复out.patch.modify
补丁。
If the changes are separate in the file as your initial question stated - added a new method, changed an existing method - this will work
如果更改在文件中是分开的,如您最初的问题所述 - 添加了一个新方法,更改了一个现有方法 - 这将起作用
This is a very tedious solution - although I'm not convinced you should have any reason to separate your commits.
这是一个非常乏味的解决方案 - 尽管我不相信你应该有任何理由来分开你的提交。
You also could have checked out multiple working copies of the same source to apply your work against:
您还可以检出同一来源的多个工作副本以将您的工作应用于:
svn co http://location/repository methodAdd
svn co http://location/repository methodModify
svn co http://location/repository methodAdd
svn co http://location/repository methodModify
Be sure to svn up
and test to make sure all is well.
一定要进行svn up
测试以确保一切正常。
回答by parvus
This is possible using TortoiseSvn (Windows) since v1.8.
从 v1.8 开始使用 TortoiseSvn (Windows) 就可以做到这一点。
4.4.1. The Commit Dialog
If your working copy is up to date and there are no conflicts, you are ready to commit your changes. Select any file and/or folders you want to commit, then TortoiseSVN → Commit....
<snip>
4.4.3. Commit only parts of files
Sometimes you want to only commit parts of the changes you made to a file. Such a situation usually happens when you're working on something but then an urgent fix needs to be committed, and that fix happens to be in the same file you're working on.
right click on the file and use Context Menu → Restore after commit. This will create a copy of the file as it is. Then you can edit the file, e.g. in TortoiseMerge and undo all the changes you don't want to commit. After saving those changes you can commit the file.
After the commit is done, the copy of the file is restored automatically, and you have the file with all your modifications that were not committed back.
4.4.1. 提交对话框
如果您的工作副本是最新的并且没有冲突,您就可以提交更改了。选择要提交的任何文件和/或文件夹,然后 TortoiseSVN → Commit....
<剪辑>
4.4.3. 仅提交部分文件
有时您只想提交对文件所做的部分更改。这种情况通常发生在您正在处理某事但随后需要提交紧急修复程序时,并且该修复程序恰好在您正在处理的同一文件中。
右键单击文件并使用上下文菜单 → 提交后恢复。这将按原样创建文件的副本。然后您可以编辑文件,例如在 TortoiseMerge 中并撤消您不想提交的所有更改。保存这些更改后,您可以提交文件。
提交完成后,文件的副本会自动恢复,并且您拥有包含所有未提交的修改的文件。
On Linux, I would give http://webstaff.itn.liu.se/~karlu20/div/blog/2013-05-31_SVNPartialCommit.phpa try. Haven't tried it out myself, though.
在 Linux 上,我会尝试http://webstaff.itn.liu.se/~karlu20/div/blog/2013-05-31_SVNPartialCommit.php。不过自己没试过。
回答by Greg Hewgill
I used to do this:
我曾经这样做过:
- In my editor (I use vim), edit the file so that only one of the changes appear
- Save the file (but don't quit the editor)
- Commit the changed file to svn
- Hit "undo" in the editor enough times for the second set of changes reappear
- Save the file again
- Commit the second set of changes.
- 在我的编辑器(我使用 vim)中,编辑文件以便只显示其中一项更改
- 保存文件(但不要退出编辑器)
- 将修改后的文件提交到 svn
- 在编辑器中点击“撤消”足够多的时间来重新出现第二组更改
- 再次保存文件
- 提交第二组更改。
This is a simplistic approach that assumes one set of changes is reasonably easy to undo. For more complex situations, I would give up and commit both changes without worrying about it.
这是一种简单的方法,假设一组更改相当容易撤消。对于更复杂的情况,我会放弃并提交这两个更改而不必担心。
Now that I use git, this is something I hope I'll never have to do again!
现在我使用 git,这是我希望我永远不必再做的事情!
回答by Aeon
I use either a local darcs repo, or just merge the changes in gradually. With merging (opendiff opens FileMerge, a merge program that comes with Xcode; replace with your favorite merge tool):
我使用本地 darcs 存储库,或者只是逐渐合并更改。使用合并(opendiff 打开 FileMerge,Xcode 附带的合并程序;替换为您最喜欢的合并工具):
cp file file.new
svn revert file
opendiff file.new file -merge file
merge the related changes, save the merge, quit the merge program
合并相关更改,保存合并,退出合并程序
svn ci -m 'first hunk' file
mv file.new file
svn ci -m 'second hunk' file
if more than one unrelated hunk in the file, rinse and repeat (but why would you wait so long before committing?!)
如果文件中有不止一个不相关的大块头,冲洗并重复(但为什么你要等这么久才提交?!)
Also, if you know git, you can use git-svnto maintain a local git repo and sync your commits to an svn master server; works great in my limited experience.
此外,如果您了解 git,则可以使用git-svn来维护本地 git repo 并将您的提交同步到 svn 主服务器;在我有限的经验中效果很好。
回答by bahrep
Try VisualSVN for Visual Studio. The latest 6.1 releaseintroduces the QuickCommit feature. You can partially commit selected changes in a file using the new Commit this Blockand Commit Selectioncontext menu commands in the Visual Studio editor.
为 Visual Studio尝试VisualSVN。在最新的6.1版本中引入了QuickCommit功能。您可以使用Visual Studio 编辑器中新的“提交此块”和“提交选择”上下文菜单命令部分提交文件中的选定更改。
回答by BCS
- Open all the files you want to split in editor-of-choice
- Using a different tool set (on Win, use Spike's suggestion (the old version)) back out the second set
- Commit
- go back to your editor-of-choice and save all the files
- 在选择的编辑器中打开要拆分的所有文件
- 使用不同的工具集(在 Win 上,使用 Spike 的建议(旧版本))退出第二集
- 犯罪
- 返回您选择的编辑器并保存所有文件
It's a little riskier than Spike's full suggestion but can be easier to do. Also make sure you try it on something else first as some editors will refuse to save over a file that has changed out from under them unless you reload that file (losing all your changes)
这比 Spike 的完整建议风险更大,但更容易做到。还要确保您先在其他东西上尝试它,因为某些编辑器将拒绝保存已更改的文件,除非您重新加载该文件(丢失所有更改)
回答by Ian Dunn
I think an easier option than generating diff files, reverting, etc, would be to have two copies of the repository checked out, and use a visual diff tool like DeltaWalker to copy hunks from one to the other.
我认为比生成 diff 文件、恢复等更简单的选择是检查存储库的两个副本,并使用 DeltaWalker 等可视化 diff 工具将大块文件从一个复制到另一个。
The first copy would be the one you actually work off of, and the second would just be for this purpose. Once you've made a ton of changes to the first, you can copy one section over to the second, commit it, copy another section, commit it, etc.
第一个副本将是您实际工作的副本,第二个副本仅用于此目的。对第一个部分进行大量更改后,您可以将一个部分复制到第二个部分,提交它,复制另一个部分,提交它等等。