Partial Commits with Subversion

2019-01-06 09:00发布

Given the case I made two independent changes in one file: eg. added a new method and changed another method.

I often don't want to commit both changes as one commit, but as two independent commits.

On a git repository I would use the Interactive Mode of git-add(1) to split the hunk into smaller ones:

 git add --patch

What's the easiest way to do this with Subversion? (Maybe even using an Eclipse plug-in)

Update:
In The Thing About Git, Ryan calls it: “The Tangled Working Copy Problem.”

标签: svn git
11条回答
做个烂人
2楼-- · 2019-01-06 09:27

I have done this using TortoiseSVN.

The built in merge utility allows you to show a diff between the repository version and your working copy.

Use the create backup function of the diff utility

  1. Go to commit your file as if you were going to commit all your changes.
  2. In the commit window, double click the file to show a diff.
  3. In the diff settings, click the option to backup original file.
  4. Right-click the changes you don't want, and use select use other text block.
  5. Save the diff exactly once. The backup will be overwritten each time you save. This is why you only want to save once.
  6. Commit the change.
  7. Overwrite the original with the created .bak file (which will have all your original changes).
  8. Commit your file.

You should now have all your changes committed, using two separate commits.

查看更多
虎瘦雄心在
3楼-- · 2019-01-06 09:28

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 (1)

查看更多
太酷不给撩
4楼-- · 2019-01-06 09:31

Tortoise SVN 1.8 now supports this 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

Per the documentation:

To commit only the parts of the file that relate to one specific issue:

  1. in the commit dialog, right-click on file, choose "restore after commit"
  2. edit the file in e.g. TortoiseMerge: undo the changes that you don't want to commit yet
  3. save the file
  4. commit the file
查看更多
时光不老,我们不散
5楼-- · 2019-01-06 09:33

Try VisualSVN for Visual Studio. The latest 6.1 release introduces the QuickCommit feature. You can partially commit selected changes in a file using the new Commit this Block and Commit Selection context menu commands in the Visual Studio editor.

enter image description here

查看更多
祖国的老花朵
6楼-- · 2019-01-06 09:36

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.

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!

查看更多
萌系小妹纸
7楼-- · 2019-01-06 09:36

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):

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-svn to maintain a local git repo and sync your commits to an svn master server; works great in my limited experience.

查看更多
登录 后发表回答