I would like a command to output the largest public revision number in my local repo
This command does what I want, but takes 2 seconds to come back with '43067', so I would think there would be a more direct way
hg log -l 1 -r "sort(public(), -rev)" --template "{rev}" takes 2 seconds
For comparison hg log -l 1 -r "public()" --template "{rev}" returns '0' instantly
Edit 10 minutes later:
hg log -l 1 -r "reverse(public())" --template "{rev}" seems acceptably fast
Go with:
hg id --num --rev 'last(public())'
Related
o 911e74cd 44 minutes ago master
|
| # f085ae95 3 minutes ago
| | Testing
| |
| o 4431b579 Today at 11:24
|/ Feature
|
o 4ab195c4 Today at 04:59
I am currently on revision f085ae95 and I would like to use one hg update command to get to 4ab195c4, which is the last ancestor that is on the public branch in the repository.
You can literally do:
hg update 4431b579
and that should work.
This will update the files in your working folder to whatever state they had in the referenced changeset.
You could also use:
hg up -r -2
to go back 2 revisions from the working folder, which I think would do the same thing.
hg log -r "last(public() and ancestors(.))" --template "{node}" will print out the hash of the last commit on the public branch that is also an ancestor of the current commit. As such you can now chain command calss via:
hg update `hg log -r "last(public() and ancestors(.))" --template "{node}"`
or
hg rebase -s `<commit-you-want-to-rebase>` -d `hg log -r "last(public() and ancestors(.))" --template "{node}"`
This is almost exactly a duplicate of Examining a single changeset in Mercurial, and without doubt a duplicate of another question I can't find on SO through Google alone.
I'm looking back through a Mercurial repo, and I want to see what exactly changed between two revisions (let's say 2580 and 2581):
hg log -v -r 2581
gives me all the files that changed.
How can I also see the diffs of these files?
Thanks.
Revision 2580 isn't necessasrily the parent revision of 2581. It's easy to check if it is, of course, but easier yet is to just do:
hg log -p -r 2581
That compares 2581 to its (first) parent revision no matter what it is, and most clearly encompasses the answer to the question "what the hell did 2581 do?"
Try hg diff -r 2580 -r 2581.
hg diff -r 2580 -r 2581
This is a wrong example. The revision 2580 can be in another branch and you get diff between two branches.
Use
hg log -p -r 2581
or hg diff -c 2581
The difference between them in the first lines. Hg log also show information about changeset (parent, author, date, ...)
I prefer second variant hg diff -c ... because it can store to patch files.
hg diff -c 2581 > revision_2581.patch
Another solution is to use revset notation which IMO is a better solution as you can use it in more places consistently (ie you don't need to know about diff -c and log -p ).
hg diff -r 'last(ancestors(2581),2)'
Yes that is rather verbose compared to -c (for diff) and -p (for log).
However mercurial allows you to create revset aliases
In your .hgrc:
[revsetalias]
next(s) = descendants(s, 1)
prev(s) = last(ancestors(s),2)
Now you can do
hg diff -r 'prev(2581)'
hg log -r 'prev(2581)'
Because I used to always do
hg vdiff -r -2:-3
hg vdiff -r 5213:5212
are all the hg commands exactly the same using those, vs using
hg vdiff -c -2
hg vdiff -r 5213
?
The -c option means changes introduces by this revision, so hg foobar -c 23 is the same as hg foobar -r22:23 if 22 is the first parent of 23. When 22 and 23 are not in a parent0-child relationship, you get the diff of two random changesets.
Use hg help revisions to see all the various ways you can specify revisions, which should work with all subcommands.
In Mercurial it's possible to hg status only the modified/added/removed files by doing:
hg st -m
hg st -a
hg st -r
Is it possible to obtain the same behaviour for the diff command? From the man page, it seems not.
One option would be to use something like this:
hg status -mar --no-status | xargs hg diff
The --no-status flag insures that just the file name is sent to STDOUT.
Is there any Mercurial extension that can grep for "console.log" that might have been accidentally left over as debugging code?
Right now this is what I am doing:
1) hg out ssh://....
the above is to see what is the first committed revision in my local repo, say, the smallest revision is 3456
2) hg diff -r 3455 | grep "^+" | grep "console\.log"
The number 3455 is 3456 - 1. the first grep is to see newly added code. the second one is for console.log
This method can tell that I have "console.log" in the new code, but won't say what file it is in.
It sounds like you're in need of a commit hook. Try putting something like this into your .hg/hgrc (or ~/.hgrc if you want it global):
[hooks]
pretxncommit = sh -c 'if hg log -p -r $HG_NODE | grep -q '^\+.*console\.log' ; then exit 1; else exit 0; fi'
That will abort your commits if they would be adding a line that contains console.log. Your commit message will be saved in .hg/last-message.txt.
See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.