A question about "hg patch/import": how to use a patch?
Benoit Boissinot
benoit.boissinot at ens-lyon.org
Fri Oct 30 05:57:13 CDT 2009
On Fri, Oct 30, 2009 at 09:33:22AM +0800, alex.w.y.wang wrote:
> Hi everyone. I am new to Mercurial.
> As mentioned in the captial, assuming I have one directory containing a simple source code file, which is empty:
> A\simple.c
> Then I clone it to B, and we have:
> A\simple.c
> B\simple.c
> Now, I add a line to simple.c, and run command: "hg diff > patch.v1 ", the patch content is:
> diff -r 664ebf7b0f2c simple.c
> --- a/simple.c Fri Oct 30 08:57:26 2009 +0800
> +++ b/simple.c Fri Oct 30 08:58:33 2009 +0800
> @@ -0,0 +1,1 @@
> +/* patch for a new line: 1 */
> \ No newline at end of fil
>
> cd to the B content, run command "hg import/patch [path/to/]patch.v1"
> Everything works perfectly until now.
>
> Then I add another line to A\simple.c, run command: "hg diff > patch.v2", the patch content is:
>
> diff -r 664ebf7b0f2c simple.c
> --- a/simple.c Fri Oct 30 08:57:26 2009 +0800
> +++ b/simple.c Fri Oct 30 09:01:58 2009 +0800
> @@ -0,0 +1,2 @@
> +/* patch for a new line: 1 */
> +/* patch for a new line: 2 */
> \ No newline at end of file
>
> cd to the B content, run command "hg import/patch [path/to/]patch.v2"
> Now it works wrongly.
> The content of A\simple.c is:
> /* patch for a new line: 1 */
> /* patch for a new line: 2 */
>
> The content of B\simple.c is:
> /* patch for a new line: 1 */
> /* patch for a new line: 2 *//* patch for a new line: 1 */
>
> Since this is a extremely simple case, which is guranteed to be
> sucessful. However, the result of B\simple.c is definitely not what we
> want.
>
> Can anyone tell me how to solve this problem? Thank you very much.
The problem you have is that both patches are based on the same rev
(664ebf7b0f2c), while B has one more commit.
So if we call the first patch p and the second p', A has p', and B has
p.
So after importing the patch, B will have p+p' which is obviously not
correct (and p' will often fail to apply, you just got lucky with your
simple example).
So you could either not commit when importing (hg import --no-commit)
and revert the changes or update to the parent before importing (hg up
664ebf7b0f2c), but this will create a new head.
Hope it helps,
Benoit
--
:wq
More information about the Mercurial
mailing list