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
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)
svn diff
.svn revert
.patch
tool, or by manual editing, or whatever.diff
afterwards to compare your working copy with your back-up to be sure you applied the patch-parts correctly.I used to do this:
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!
This is possible using TortoiseSvn (Windows) since v1.8.
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.
On Linux, I would give http://webstaff.itn.liu.se/~karlu20/div/blog/2013-05-31_SVNPartialCommit.php a try. Haven't tried it out myself, though.
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.
Try using svn diff > out.patch
then copy the out.patch
file to out.patch.add
and out.patch.modify
Only when you have a working patch file revert the original file using svn revert out.c
.
Edit the patch files by hand so that they only contain the hunks for adding or modifying. Apply them to the original file using the patch
command, test if the addition worked, then svn commit
the addition.
Wash rinse repeat for the out.patch.modify
patch.
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
Be sure to svn up
and test to make sure all is well.