Is there a way to get a copy of a hg repository as it was at a particular date?
For example, in subversion I would use:
svn checkout -r {2012-04-04} ...
And it would check out a revision as it appeared on the fourth of April.
In git its a little more complicated, but can be done:
git checkout `git rev-list -n 1 --before="2012-04-04" master`
Can you do the same thing in hg?
(EDIT: My love of revsets has caused me to overlook the obvious answer: hg update --date 2012-04-04 should get you the tipmost revision as of that date.)
If you have the whole repository cloned already (date specifications don't seem to work with clone), you can do
hg update --rev "date('< 2012-04-04')"
If there's a possibility that the repository had multiple heads/branches at the date you want, you'll have to AND in some more conditions to narrow it down to the right changeset:
hg update --rev "date('< 2012-04-04') and branch(v1.1)"
Check out hg help revsets and hg help dates for more information.
Later, if you want to go back to the tip, just
hg update
Related
I'm trying to do hg pull from another computer but hg is not giving me the latest version. It might be that I'm on the wrong branch. What can I do to resolve the error? When I make hg diff there is no diff but I know that is is not the latest version.
hg diff will never show you any output irrespective of the currently changeset, assuming that you have no uncommitted changes.
hg pull does not update your working dir to any revision - it just pulls the changesets into your mercurial repository without updating your currently checked our revision
You'll need to update your working copy to whatever revision you want. If there is only one branch involved, a simple hg update will do the trick. If there are several branches involved and the new changesets are on another branch, you'll need to tell mercurial explicitly that you're also ok with a branch change during update: hg update --check. Alternatively you can also try hg update --rev tip after the pull. If there's no branch switch involved and necessary, you can also tell pull to update immediately after a successful pull (but it won't switch branches): hg pull --update
In Mercurial, I can see my current (uncommitted) changes by running
$ hg diff
Fine. But after commit, I sometimes want to see this diff again (i.e., the diff of the last changeset). I know I can achieve this by
$ hg log -l 1
changeset: 1234
tag ...
$ hg diff -c 1234
I'm looking for a way to do this in one line.
Use hg diff -c tip, or hg tip -p (shorter, but works only for tip).
This will work until you pull something, since tip is an alias for the most recent revision to appear in the repo, either by local commit or
pull/push from remote repositories.
You can use relative revision numbers for the --change option:
hg diff -c -1
See https://stackoverflow.com/a/3547662/239247 for more info.
An alternative is to use: hg diff --rev -2:-1
This form has the advantage that it can be used with the status command (e.g. hg st --rev -2:-1), and using it makes it easy to remember what to do when one needs to determine differences between other revision pairs (e.g. hg diff --rev 0:tip).
The answer from Macke is quite helpful, but in my case I didn't want to diff tip.
Thankfully you can also just diff the currently selected comment:
hg diff -c .
At the moment I am looking at transitioning from subversion to Mercurial at work, and as such the Mercurial repository is not yet published.
I have used the authormap argument to transform our usernames to the Mercurial format, which went fine.
Unfortunately two people have been commiting under the same name. The repository is not very large, so I would like to change the authors to match the right people. For that reason I would like to ask:
Is there any way to change the author for a specific changeset, or a list of changesets?
You can use the bundled extension Mercurial Queues (MQ) to change commit authors. Note that MQ will only work as long as history is linear. If there are branches you need to first rebase them off to a temporary side branch, and then after editing rebase them back.
First qimport the changes up till the first changeset you want to modify:
hg qinit
hg qimport -g -r <first-revnr>:tip
Then use qpop or qgoto to navigate to the respective changesets:
hg qgoto <revnr>.diff
And then use qrefresh to change the user info on the currently active changeset:
hg qrefresh -u "Some User <user#example.com>"
You can verify with hg log whether the user was correctly updated. After this, repeat for all other changesets.
When you are done, qpush all patches and use qfinish to finalize the repository.
hg qpush -a
hg qfinish -a
You could as well use the evolve extension. After setting up the extension
hg amend -U && hg prev
for a stack of commits and then hg evolve --all at the end.
Evolve introduces a meta-graph that says which commit replaces which commit.
So when we do hg amend -U a bunch of times, we create commits with a different author that replaced the old commits. hg evolve --all the will use the replacement information to figure out where to move commits that were based on our pre-replaced commits.
Credits to mercurial developers on IRC #mercurial.
In mercurial is there a way to diff between 2 different tags?
I have tagged my builds and have a couple commits in between builds and want to figure out the differences between the 2 builds.
hg diff -r tag1:tag2
That's all there is to it.
This answer in the Kiln StackExchange seems quite complete (based on hg diff and hg log):
To see all of the changesets that were introduced between, say, the tags v1.0 and v1.1, run:
hg log -r v1.0:v1.1
To see the net sum of differences introduced in those revisions, you'd instead run:
hg diff -r v1.0:v1.1
Mercurial can even format this output in changelog-style, if you want. Simply add the --style changelog parameter:
hg log -r v1.0:v1.1 --style changelog
When I try to hg rebase -s 1775 --collapse, I am asked to merge all the files I touched since rev 1774. How can I avoid that?
Details
I am just learning how to rebase. I successfully tried the example given here, and a few minor variations. However, in my own repository, when I try the same steps, I am asked to merge a boat-load of files when I rebase. Here's what I do. What am I doing wrong?
hg update -r 1774
hg tag "Started-New-Feature"
hg rebase -s 1775 --collapse
I thought maybe it was because I had updated to -r1774, so I updated to tip after tagging -r1774. Same result.
hg update -r 1774
hg tag "Started-New-Feature"
hg update
hg rebase -s 1775 --collapse
The hg tag creates a new rev -r1784. So I tried updating specifically to -r1783. Same result.
hg update -r 1774
hg tag "Started-New-Feature"
hg update -r 1774
hg update -r 1783
hg rebase -s 1775 --collapse
I've searched the web and SO for related questions and didn't find anything, which doesn't mean answers don't exist. Pointers to existing answers are welcome.
Edit:
This seems related to a reported mercurial bug that was fixed in 1.4. I have version 1.1. I tried updating to 1.4 or later, but sudo apt-get install mercurial says I have the latest, and the download link on the mercurial page is currently broken. So maybe the answer is just getting the latest version, but hopefully there's another way around this.
Are you using ubuntu? If so you can use the launchpad ppa version of hg, which tends to be very currenty https://launchpad.net/~mercurial-ppa/+archive/releases