46

I've looked for that in the manual, but I can't generate a patch for the last commit. I tried

hg qnew patch_name

but it does only file with

# HG changeset patch
# Parent a6a8e225d16ff5970a8926ee8d24272a1c099f9c

I also tried

hg export tip

but it doesn't do anything. I committed the changes exactly.

How to generate a patch file with the last commit in?

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
deem
  • 1,844
  • 4
  • 20
  • 36
  • 1
    `hg diff -c tip > patch` -- note that qnew is part of the mq extension and is for a different purpose. – Warren P Oct 23 '11 at 14:31
  • 1
    If you've already done a `qnew` with no changes then the tip revision will be empty when you do `export tip`. You'll need to do qdel to delete the patches you have applied. – Paul S Oct 23 '11 at 21:59

6 Answers6

75

The command to do this is export:

$ hg export -o FILE -r REV

It doesn't require redirection and will thus work correctly on any platform/shell.

Idan K
  • 20,443
  • 10
  • 63
  • 83
  • Also it outputs the changeset headers like user and date that Mercurial can use to reconstruct the changeset when importing it later. – Laurens Holst Oct 24 '11 at 09:26
22

Your hg export tip is the best way to do it, and the hg diff and hg log based answers are just lesser versions of the same. What exactly do you see/get when you type hg export tip? What does the output of hg log -p -r tip show?

The changeset tip is just means "the changeset that most recently arrived in my repository" which isn't as useful a concept as you might think, since hg pull and hg tag all create changesets too. If you really want the last thing you committed you'll need a more precise revspec.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
18

Like so:

hg diff -r tip > tip.patch
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
  • I entered it in the windows console, but it creates empty file. Even, the "hg diff" command doesn't return anything. – deem Oct 23 '11 at 14:26
  • 1
    There's a nice UI for this in TortoiseHG. Try `hg diff -c tip > tip.patch` instead of `-r`. – Warren P Oct 23 '11 at 14:27
  • @WarrenP OK, I open the revision history window, and what next? How to generate a file with any revision? – deem Oct 23 '11 at 14:31
  • My colleague did like this on his PC and it does not work to import the patch on my pc, so it is not working – michaeak Nov 29 '17 at 16:46
  • I believe this is how to make a ptach for an _uncommitted_ change. A related valuable tip but not what the OP asked. – Chip Grandits Aug 16 '19 at 20:04
6

You can use this command:

hg log -r tip -p > tip.patch

this will generate a patch for just that revision.

Trenton Schulz
  • 778
  • 3
  • 8
1

If you want to convert the latest commit to a patch file, use

hg qimport -r tip

This will replace the topmost regular commit with an applied MQ patch file.

daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
0

To generate patches using "mq extensions" in mercurial, you can follow the below given steps. This will create a patch using mercurial:

1) Enabling mq extensions: Add the following lines to your hgrc file and save it.

[extensions]
mq =

2) Creating a patch using mq extensions: To create a patch using mq extensions you can do the following.

hg qnew -e -m "comment you want to enter" bug_name.patch

In the above command, -e flag is for editing the patch and -m flag is for adding a message to the patch.

3) Updating the patch: For updating the patch, you can use the following command when a patch is already applied.

hg qrefresh
Anup Allamsetty
  • 71
  • 2
  • 10