In the good old days of Subversion, I would sometimes derive a new file from an existing one using svn copy
. Then if something changed in sections they had in common, I could still use svn merge
to update the derived version.
To use the example from hginit.com, say the "guac" recipe already exists, and I want to create a "superguac" that includes instructions on how to serve guacamole to 1000 raving soccer fans. Using the process I just described, I could:
svn cp guac superguac
svn ci -m "Created superguac by copying guac"
(edit superguac)
svn ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
svn ci -m "Fixed a typo in guac"
svn merge -r3:4 guac superguac
and thus the typo fix would be applied to superguac.
Mercurial provides an hg copy
command that marks a file as a copy of the original, but I'm not sure the repository structure supports a similar workflow. Here's the same example, and I carefully only edit a single file in the commit I want to use in the merge:
hg cp guac superguac
hg ci -m "Created superguac by copying guac"
(edit superguac)
hg ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
hg ci -m "Fixed a typo in guac"
I now want to apply the change in guac to superguac. Is that possible? If so, what's the right command? Is there a different workflow in Mercurial that achieves the same results (limited to a single branch)?
First, we need to move back into the main branch, which is accomplished using the “hg update” command. Then, we run the “merge”command, specifying the name of the branch we'd like to merge from. Finally, we commit the changes. The changes are now present in the main branch.
Quickly switch to another branch or bookmarkIn the Status bar, click the Mercurial Branch widget to open the Branches popup. Select the branch or bookmark to which you want to switch and in the menu that opens, click Update.
Branches occur if lines of development diverge. The term "branch" may thus refer to a "diverged line of development". For Mercurial, a "line of development" is a linear sequence of consecutive changesets. Combining a line of development into an existing one is called merging. Creating a branch.
To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.
There's no pure-mercurial way to go cross-file with your patches, but if patch
is installed on your system you could achieve essentially the same thing by following up your series of mercurial commands with:
hg log -p -r tip -I quac | patch superquac
That's essentially saying: "take the diff (-p
) that was applied to file quac (-I quac
) in the most recent changeset (-r tip
) send it to standard output (hg log
), and use that as the input to the patch (| patch
) command acting on file superquac (superquac
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With