What mercurial command can you use to see the changeset prior to changeset xyz?
If you do hg log -r :xyz you see all the changesets prior to (and including) xyz - listed in ascending order. But I'd like to easily see just the prior changeset.
Update: Really what I'm after is this: If I do an hg fetch, what command can I use to see the changeset PRIOR to the the changesets that were pulled in by the fetch?
hg log -r :xyz where xyz is the first changeset pulled in by the fetch works but it returns the entire list of prior changesets where I just want the most recent.
You can't do it. Once you've pulled (and fetch is just pull + either update or merge) there is no record of what you had before the pull and what you just got from the pull.
You should do hg incoming before you pull to see what you will get.
Also, stop using fetch. The acts of pulling and updating and merging are completely separate and doing them in a single commands provides inadequate error reporting and just confuses things. The command is disabled by default and there's talk of removing it entirely. Merging is coding, and it shouldn't be hidden.
Expanding to Show cases you can't cover
If before fetching your history is this:
[A]-[B]-[C]
and you (against all advice) fetch and get [D] you now have:
[A]-[B]-[C]-[D]
And you can see exactly what's new with:
hg diff -r tip-1
or with:
hg diff -r "parent(tip)"
But if starting again with A,B,C you fetch and get D,E yielding this:
[A]-[B]-[C]-[D]-[E]
there is no command you can run to see "what changed" without having previously written [C] down on a post it note.
If, on the other hand your repo started out looking like this:
[A]-[B]
\
-[C]
and after fetching you have this:
[A]-[B]-[D]
\
-[C]-[E]
there's no single command that will tell you "what changed". Similarly, if before pulling your repo looked like this:
[A]-[B]-[C]
and after fetching you got this:
[A]-[B]-[C]-[E]-[F]
\ /
-[D]-------/
where [F] is the new ill-advised auto-merge changeset fetch created then the command:
hg diff -r C
will tell you what's new, but there's no way to look up 'C' without having previously written it down.
I assume xyz is a changeset in hash form. Try:
hg log -r :xyz-1
That should work to list just the changeset prior to 1
I'm not sure what is meant by prior. Your question could mean you might just want the parents of the changeset. These you would get easily with
hg parent -r xyz
This does not need fancy new versions of mercurial.
hg parents [-r REV] [FILE]
show the parents of the working directory or revision
Print the working directory's parent revisions. If a revision is given via
-r/--rev, the parent of that revision will be printed. If a file argument
is given, the revision in which the file was last changed (before the
working directory revision or the argument to --rev if given) is printed.
options:
-r --rev show parents of the specified revision
--style display using template map file
--template display with template
--mq operate on patch repository
With the parentrevspec[1] extension installed, you can use the git-like syntax below. Depending on your shell, the quotes may not be necessary.
hg log -r 'xyz^'
https://www.mercurial-scm.org/wiki/ParentrevspecExtension
Related
I'm using Mercurial with the evolve extension. Is there a revision specifier that means "the Nth first parent in the obslog for revision X"?
After I rebase a commit I would like to be able to quickly get the diff between the pre-rebased version of the commit and the post-rebased version. (Something similar to Git's #{1} revision specifier.)
You can reference the first parent in obslog (called precursor) by using the following revset: hg log -r "precursors(.)" --hidden. The problem is that you can have multiple precursors for a single revision.
If you are sure you have a linear obsolescence history, you can access the Nth parent by calling precursors several times: hg log -r "precursors(precursors(.))".
I'm trying to write a small script for my team that automatically updates the feature branche to a case and then creates a branch for review. I've got the commands down manually but I'm having trouble making it a bit more hands off.
For now, I want to use this templated command:
hg log --rev <changeset> --template "{branch}\n"
Which returns the branch name of a changset. Then I would like to remove a portion of the name and prepend a string. For example, a branch would be named case-1234-FeatureDescription and I would want to be creating a branch named review-1234-FeatureDescription
Ideally, I would like to pipe the output of this command to the branch command
hg branch <result-of-previous-command>
Is it possible to do this?
You suggest to create a branch by a name which you just extraced from the logs of the very same repo. That doesn't exactly look like it can succeed as it already exists.
Additionally, it likely is probably not a good idea to create a named branch for each review process as branch names are persistent. You might consider to use bookmarks for that purpose as they can be deleted without trace from the repo after review is completed.
I'd suggest to use - without piping - something like
hg bookmark -r CHANGESET $(hg log --rev CHANGESET -T"{branch}")-review
Is there a way to select and copy all commit messages between 2 revisions in tortoiseHg workbench.
I want basically to have the change log descriptions between 2 revisions.
At the bottom of the Workbench window there's a console panel, if you can't see it go to View> Show Console.
Into that console window type:
hg log -r 1510:1513 --template '{desc}\n\n'
This will retrieve the values for the revisions between -r 1510:1513 and only show you the bits specified in the template, in this case the description or commit message {desc}, and it puts two line breaks \n in at the end so each message is clearly separated from the next.
If you wanted to see the revision number along side the commit message you could use something like:
hg log -r 1510:1513 --template '{rev}: {desc}\n\n'
{rev} gives you the friendly revision number.
hg log with revsets (the bit that defines what revisions you want to look at, in this case -r 1510:1513) and templates is extremely powerful and can be manipulated to get almost any information you want out of Mercurial changesets.
I'd like to get a list of the files I've modified and committed before I push.
I can generally do this OK with hg outgoing.
But if I pull in some additional changes, after I've committed mine, then those new changes are also listed, and they are even listed under my name. I did do a commit of the merge, but nothing really merged, I just pulled in an unrelated changeset. If I'm pulling in a lot of changes from other users, my changes get lost in all of these changes.
Is there a way to list just my changes ?
You can always use log with revset's function and some template keywords in order to get such filelist
hg help revsets suggests usage of outgoing():
"outgoing([path])"
Changesets not found in the specified destination repository, or the
default push location.
--template "{files}\n" give you space-separated list of files in each changeset in range and newline-separation of sets from different changesets. --template "{files % '{file}\n'}" do the trivk "file per line"
You can pipe output of log to sort in order to get sorted, without duplicates, list of files
Final draft hg log -r 'outgoing()' --template "{files % '{file}\n'}" | sort -u
You can use
hg outgoing --no-merge
to filter out the merge changesets (-M is the short version see hg help outgoing).
If you are pushing to the same repo from which you pulled the changesets authored by others, you should only see the changesets you created.
As the definite guide aptly points out (search for "Tags and cloning"):
When you run hg clone -r foo to clone a repository as of tag foo, the new
clone will not contain any revision newer than the one the tag refers to,
including the revision where the tag was created. The result is that you'll
get exactly the right subset of the project's history in the new
repository, but not the tag you might have expected.
It means hg tags in your new clone does NOT show the foo tag. Same thing happens if you had cloned before foo tag was added, and you do hg pull -r foo.
(Digression: tag is about the only thing I don't quite get in hg. I understand there are advantages (e.g. merge) in putting it in a changeset, but it always feels weird to have meta data mixed with source code.)
It should be obvious that I'm asking for an automated way, instead of pulling the tag changeset as a separate manual step.
I know I could check for this scenario in an incoming hook (so it works for both clone and pull), or wrap clone and pull.
But is there a better/easier way?
UPDATE hg bug tracker already has this issue.
You want a giant hack with bash and an embedded Perl script? Well, here it is...
#!/bin/bash
if [[ "$1" == "" || "$2" == "" || "$3" == "" ]]; then
echo 'hgclonetag <src> <tgt> <tag>'
exit 1;
fi
REV=`hg log -R $1 --rev $3: --limit=2 | perl -F: -lane 'if (/:([\dA-Fa-f]+)$/) {print $F[2] if defined($flag);$flag=1;}'`
hg clone --rev $REV $1 $2
This invokes the hg log command to extract the revision number after the first tag-related revision and then clones to this revision.
Currently this does not work on remote repos: -R switch only works on local repos unfortunately.
The more I think about it the more I'm convinced the right answer is to just clone everything and update to the tag, which can be done in a single step:
hg clone http://host/path#tagname
That gets you everything and then does hg update to tagname which sets your working directory to the correct revision. Given delta compression that's not necessarily much larger, and if it is you can automate cloning the bulk of it from a previous local clone.
There is a postclone hook. It's called post-clone (the hgrc manpage shows a post-ANYCOMMAND and pre-ANYCOMMAND exist) though as you pointed out you could also use *changegroup or update hooks too, since clone uses both of those functions (unless you suppress update with -U).
What about just adding a --localtag so you have the name but not the extra changeset if you need it for reference only. Something like
hg clone -r tagname URL
hg tag --local tagname
which you could easily build into a shell alias.
Other than that there's not necessarily guaranteed to be a way to have revision X and the revision where revision X is tagged without also having other revisions you don't want since the tag could have been applied after other work was done. You can, of course, always update to 'X' and to have subsequent changesets in you working dir, but they'll still be in your repo.
Honestly, once I figured out that the tag name doesn't come a long when you clone up to a tag, which I admit confused the heck out of me at first, I didn't find any need to bring along the changeset with the tag in it.
Yes it can be done by post-clone/pull hooks, but there are a couple of crooks.
First, it only works for local repo, since you can't get the list of tags in a remote repo.
Second, dealing with clone/pull arguments and options is not trivial. (For clone I need to get the target repo, -r, -u, -U. For pull I need -r and -u.) I tried to use fancyopts, but it can't deal with global options, which are processed away in dispatch. I managed to hack dispatch to give me only the args and opts of a command, but it feels and looks ugly.
Using command wrapper would eliminate the second problem.
I hope one day hg will add an option to clone and pull to do it cleanly.