svn merge vs svn diff

作者在 2012-08-17 22:38:24 发布以下内容
You are *not* merging two unrelated sources. https://svn/A/trunk@1000 and https://svn/A/trunk@2000 are related to each other yes?

This matters because:

  1) 'svn diff' ignores ancestry by default

  2) 'svn merge' considers ancestry by default

Check out this section of the Subversion book, http://svnbook.red-b​ean.com/nightly/en/s​vn-book.html#svn.bra​nchmerge.advanced.an​cestry, it explains in more detail what I am talking about.

What this means for you is that the diffs calculated by

  c:\SOURCE\A\trunk\>svn diff -r 1000:2000 > trunk.A.patch

and

  c:\SOURCE\B\trunk\>svn merge -r 1000:2000 https://svn/A/trunk

are not *necessarily* the same. To make diff equivalent to merge or vice-versa you need to use the --ignore/--notice-ancestry options.

In your case that means the diffs generated by these two are equivalent:

  c:\SOURCE\A\trunk\>svn diff -r 1000:2000 --consider-ancestry > trunk.A.patch
  c:\SOURCE\B\trunk\>svn merge -r 1000:2000 https://svn/A/trunk

And so are these:

  c:\SOURCE\A\trunk\>svn diff -r 1000:2000 > trunk.A.patch
  c:\SOURCE\B\trunk\>svn merge -r 1000:2000 --ignore-ancestry https://svn/A/trunk
  
It might be informative to try generating these two diffs:

  c:\SOURCE\A\trunk\>svn diff -r 1000:2000 --consider-ancestry > trunk.A.consider-ancestry.patch
  c:\SOURCE\A\trunk\>svn diff -r 1000:2000 > trunk.A.ignore-ancestry.patch

Are the diffs exactly the same? If not, this might be part of your problem.
技术 | 阅读 5174 次
文章评论,共2条
vfdff(作者)
2012-08-17 23:30
1
Creating a patch file<br />
<br />
Creating a patch file is really easy. First, check out the most recent version of the code from Subversion using the 'checkout' command.<br />
<br />
Make your changes.<br />
<br />
Then, in the root the project run the following command. It will store the patch file in your home directory. Make sure to give it meaningful filename.<br />
<br />
svn diff &gt; ~/fix_ugly_bug.diff<br />
<br />
The file has the .diff extention, which stands for differences. This extension is recognized by many text editors and enables 'syntax highlighting' automatically. (Give it a try with TextMate and you'll know what I mean.)<br />
<br />
You can send the diff-file to the author of the project by email, or you can create a ticket in Trac and add it as an attachment. The author will review the changes you made and possibly apply them to the source.<br />
Applying a patch<br />
<br />
You should never apply patches from any person other than your development team without first reading through the changes, apply them locally and test your application and then commit them. Patches can not only include bug fixes, but also alterations to create back doors or add other exploits to your code.<br />
<br />
Always read through a patch before applying it!<br />
<br />
When you are sure the patch will bring no harm to you, your application or your customers, go ahead an apply it to your working copy. Here, I assume that you downloaded the patch file we previously generated, and placed it in your home directory. In the root of your application now run:<br />
<br />
patch -p0 -i ~/fix_ugly_bug.diff<br />
<br />
This will apply all the changes in the patch to your source. The -p0 option makes sure that all files can be found correctly (this has to do with something called 'zero directories', I won't get into that right now). The -i option tells 'patch' what to use as input, in this case the 'fix_ugly_bug.diff' file in your home directory.
vfdff(作者)
2012-08-17 23:30
2
Another tip is to use specific revision numbers like so:<br />
<br />
svn diff -r OLD:NEW &gt; changes_file.diff<br />
<br />
And I just did a bunch of them by adding the file, then appending to the diff file on subsequent iterations.<br />
<br />
svn diff path/to/local/file.php -r OLD:NEW &gt;&gt; changes_file.diff
游客请输入验证码
浏览1943082次