如何在 Mercurial 的“hg log”上显示当前工作修订版?
我希望我的“hg h”(hg 日志别名的输出)能够显示我当前正在工作的修订版本在历史记录/日志的上下文中。
在我的 .hgrc 上,我有以下内容:
[alias]
h = log --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n"
这是一个示例输出:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
但如果我更新到修订版 0,输出仍然是相同的:
$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
所需输出的示例如下:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit :: [working]
注意: [working] 不是标签,只是我的工作修订版,即我更新到的修订版。
另一个示例可能是:
$ hg h
1 f130b4194c90 2011-07-21 | | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 |X| [slashfoo] initial commit ::
我使用 hgbook 上的“自定义 Mercurial 的输出”条目自定义了“hg h”输出 http://hgbook.red-bean.com/read/ customizing-the-output-of-mercurial.html
我想要做的替代方案可能是:
- 使用 graphlog 扩展并执行
hg h -G
以便 @ 表示当前工作修订版 - 使用
hg id
来了解我正在使用的修订版 hgParents
来了解我使用的修订版以及一些额外信息
但只有替代方案 #1 显示了上下文,但是 hg log -G 和别名是比我想要的输出不太“紧凑”。
这是替代方案 #1 的输出示例
$ hg h -G
o 1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
|
@ 0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
此问题类似于 我怎样才能在mercurial中找到我的工作修订版,但我希望它在上下文中,并且以紧凑的方式(即没有-G)
I want my "hg h" (an hg log alias's output) to show what my currently working revision is in the context of the history/log.
On my .hgrc I have the following:
[alias]
h = log --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n"
Here's a sample output:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
But if I update to revision 0, the output is still the same:
$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
An example desired output would be:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit :: [working]
note: that [working] is NOT a tag, just my working revision, the one I updated-to.
Another example could be:
$ hg h
1 f130b4194c90 2011-07-21 | | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 |X| [slashfoo] initial commit ::
I customized my "hg h" output using the hgbook's entry on "Customizing the output of Mercurial" http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
Alternatives to what I want to do could be:
- using graphlog extension and doing
hg h -G
so that an @ would denote current working revision - using
hg id
to know what revision I am - using
hg parents
to know what revision I am with some extra info
But only alternative #1 shows me the context, but hg log -G and aliases are a bit less "compact" than my desired output.
Here's a sample of the output of alternative #1
$ hg h -G
o 1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
|
@ 0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
This question is simmilar to How can I find my working revision in mercurial but I want it in context, and in a compact manner (i.e. without -G)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
hg log --rev $(hg id -i | sed 's/.$//')
hg log --rev $(hg id -i | sed 's/.$//')
在类似 bash 的环境中,以下 bash 别名的小怪物就可以做到这一点:
它使用
-G
选项以及grep
和sed
来去掉所有图形内容,除了@
标记,它被行尾的[working]
标记替换。诚然,这是一个有效但丑陋的解决方案。使用纯 Mercurial 命令和选项会好得多,但模板系统似乎无法提供您想要的东西。
作为旁注,您可能想看看我写的 指南针扩展 - 不是您具体要寻找什么,但它也有助于查看存储库中当前的上下文。
In bash-like environment the following little monster of a bash-alias does the trick:
It uses the
-G
option andgrep
andsed
to strip off all the graph stuff, except the@
marker, which is replaced by a[working]
marker at the end of the line.Admittedly, this is a working but ugly solution. Using pure Mercurial commands and options would be much better, but it looks like the templating system does not provide what you want.
As a side note, you might want to have a look a the compass extension I wrote -- not what your are looking for specifically but it also helps to see your current context within a repository.
使用修订集来选择您想要的变更集。如果添加
到别名的末尾,那么您将看到工作副本父修订版以及上下文前后的三个变更集。
不幸的是,不会有任何指示表明工作副本父版本在输出中的位置 - 当您处于尖端时它将位于顶部,而当您位于历史记录中的其他位置时它将位于中间。
Use a revision set to pick the changesets you want. If you add
to the end of your alias, then you will see the working copy parent revision plus three changesets before and after for context.
Unfortunately there wont be any indication of where the working copy parent revision is in the output -- it will be at the top when you're at tip, and it will be in the middle when you're somewhere else in the history.