简体   繁体   中英

How can I limit the size of a Mercurial log?

When I run Mercurial's "hg log" command from a terminal window, the results often fall off the screen, forcing me to scroll up to the top. As a result, I created a template to reduce the verboseness and format of the log:

[alias]
slog = log --template '{rev}:{node|short} {desc|firstline} ({author})\n'

However, I'd like to improve this even further by either a) limiting the size of the "slog" to just the last 10 commits or b) using a command like "hg slog ##", where "##" would be the number of logs shown in the results.

Any thoughts on how to achieve either A or B?

You could define your alias to do only a fixed limit in this way:

slog = log --limit 10 --template "{rev}:{node|short} {desc|firstline} ({author})\n"

Or, you could put --limit on the end so that you can pass a number to it, as arguments to an alias will be appended to the end:

slog = log --template "{rev}:{node|short} {desc|firstline} ({author})\n" --limit

The above could be called like this for the last 10 changesets:

hg slog 10

You should also be able to define the parameterized version in this way, but it doesn't seem to be property expanding the $1 :

slog = log --limit $1 --template "{rev}:{node|short} {desc|firstline} ({author})\n"

#I had to use shell execute to make it expand:
#slog = !hg log --limit $1 --template "{rev}:{node|short} {desc|firstline} ({author})\n"

To get last 10 changeset:
hg log -l10

Alternative solution:
Configure autopager plugin in the .hgrc file.
The end result is similar to already mentioned solution

hg log | less

If you're using a *nix environment, this allows you to scroll back through log history at your leisure:

hg log | less

or according to your preference:

hg log | more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM