I have deleted some textual files using
svn remove
. Butsvn diff
shows as removal of all content in the file. Applying a patch of that diff only modifies the content, does not remove the file.I renamed a directory which contains binary files using
svn rename
. A patch file from a normalsvn diff
does nothing.
How to make svn diff produce file that patch would apply, when svn cp or svn mv was used?
subversion d开发者_如何学Ciff including new files
Both the methods in above links does only modifications to the files. They do not get removed/renamed after applying a patch. Is it possible to get a working patch for the above changes?
From the patch
man page:
-E or --remove-empty-files Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, since patch can examine the time stamps on the header to deter‐ mine whether a file should exist after patching. However, if the input is not a context diff or if patch is conform‐ ing to POSIX, patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.
Try this:
patch -p0 -E < 1.patch && svn rm `svn st -q | grep ^! | cut -c 9-`
I think the OP's second issue is caused by an SVN bug that was fixed in SVN 1.7. You change a directory structure (move, rename, delete) and commit it, but when using svn diff
, the patch seems to "do nothing".
I had this problem when deleting directories and the symptoms are the same so I'm assuming we are experiencing the same "root bug". For me, updating to svn 1.7 solved it, because svn 1.7 generates diffs (patches) differently.
Some versions of svn diff
don't put the moved/renamed/deleted files in the diff at all!
See: http://svn.haxx.se/dev/archive-2004-03/0333.shtml. This archived email from the SVN DEV list shows the devs themselves identified this problem, sometime before 1.0.1 was released, over a decade ago. If you follow the thread, they seemed quite determined to fix it then, but even 1.6 was also leaving stuff out of the diff. I had to update to 1.7.
Basically, if svn < 1.7 detected that a directory was svn delete
'd, it would not recurse and process the children, it would just stop there and not put anything under that tree in the diff. This is not what we want, we want explicit removes for ALL of the children, so that patch can, as mentioned in other answer, remove empty files and directories via -E. Patch can't do anything if the file isn't in the patch.
Using svn 1.7 I did an identical diff as I did before but every file under a deleted directory was explicitly in the patch as having all lines removed (emptying), and then patch
/quilt
successfully removed the files and folders. I'm assuming something similar needs to happen in your case with moving or renaming.
GOTCHAS:
Upgrading to 1.7 will leave your working copies useless. Make sure you commit your changes before updating. Then you have to checkout everything again. Edit: The SVN 1.7 client might be able to repair your working directories but if it can't you might need to checkout again. Just be aware so you don't lose work.
精彩评论