Mercurial中等价于 `git log --graph --decorate --oneline --all` 的命令是什么?

4

我该怎么做

git log --graph --decorate --oneline --all

在Mercurial中使用这些选项:

  • --graph:显示提交之间的关系
  • --decorate:打印每个提交的分支名称,包括本地远程跟踪分支的信息(显示任何配置的两个远程的详细情况)。它还显示像HEAD这样的特殊分支,我也想看到它们
  • --oneline:在屏幕上显示多个节点
  • --all:显示所有分支,而不仅仅是当前所在的分支
    • 包括书签
    • 包括与本地情况相比的远程情况
5个回答

5

--graph 在hg中也是 --graph--all 的效果是默认的。

对于 --decorate--oneline,我在我的.hgrc文件中设置了:

[alias]
la = log --graph --template {oneline}

[templatealias]
oneline = '{hash}{myBranch}{myBookmarks}{myTags} {name} {commitMsg}\n'
hash = "{label(ifeq(phase, 'secret', 'yellow', ifeq(phase, 'draft', 'blue', 'red')), node|short)}"
myBranch = "{ifeq(branch, 'default', '', label('green', ' ({branch})'))}"
myBookmarks = "{bookmarks % ' {bookmark}{ifeq(bookmark, active, '*')}{bookmark}'}"
myTags = "{label('yellow', tags % ' {tag}')}"
name = '{label('blue', author|person)}'
commitMsg = '{desc|firstline|strip}'

[experimental]
graphshorten = true

此解决方案不使用已弃用的--style参数。相反,如您在别名部分中看到的,它通过--template选项由hg la激活。由于模板可以嵌套,因此“oneline”的名称将显示哈希值、分支、书签、标签、提交者和提交消息。
在此示例中,哈希值将根据提交的阶段而更改颜色。
尽管该模板仅建议每行的最终换行符,但hg在每个提交之间放置了一个额外的空行。graphshorten = true选项避免了这种情况。
要有类似于远程跟踪分支的概念,您需要一个扩展程序。
以下是输出结果(缺少华丽的颜色):
| o  821ee2270f00 (lowercase_eats_whitespace) Robert Siemer add 'lowercase_eats_whitespace' directive
| o  9a86b49dc3ba (settings_passing) Robert Siemer restructure settings-passing in parsers and grako
|/
o    31664ddc943b Juancarlo Añez Merged in siemer/grako/siemer_fixup_regex (pull request #43)
|\
| o  317cea8eba42 (siemer_fixup_regex) Robert Siemer buffering.py: remove a superfluous regexp.DOTALL from a '[...]+' pattern
|/
o  31641ef78ba8 apalala Added tag 3.9.1 for changeset f33a2e80bb7d
o  f33a2e80bb7d 3.9.1 apalala Getting ready for release 3.9.1

4

使用Mercurial 3.8,只需配置您的.hgrc文件:

[experimental]
graphstyle.parent = |
graphstyle.grandparent = '
graphstyle.missing = 
graphshorten = true

使用适当的模板将得到

$ hg log --graph --template "{rev}{ifeq(branch,'default','',' {branch}')}{if(bookmarks,' {bookmarks}')}{if(tags,' {tags}')} - {desc|firstline}"
...
| o  20881 - transaction: add onclose/onabort hook for pre-close logic
| o  20880 - clone: put streaming clones in a transaction
| o  20879 - fncache: remove the rewriting logic
| o  20878 - pull: prevent duplicated entry in `op.pulledsubset`
| o  20877 - bundle2: part params
| o  20876 - bundle2: support for bundling and unbundling payload
| o  20875 - merge with stable
|/|
o |  20874 stable - Added signature for changeset 3f83fc5cfe71
o |  20873 stable - Added tag 2.9.2 for changeset 3f83fc5cfe71
o |  20872 stable 2.9.2 - backout: correct commit status of no changes made (BC)
o |  20871 stable - backout: document return code of merge conflict
| o  20870 - merge with stable
|/|
o |  20869 stable - i18n: fix "% inside _()" problems
o |  20868 stable - i18n: fix "% inside _()" problems
o |  20867 stable - merge: fix lack of "%s" in format string causing TypeError a
o |  20866 stable - i18n-pt_BR: synchronized with c57c9cece645
o |  20865 stable - i18n-ja: synchronized with e259d4c462b5
| o  20864 - bundle2: support unbundling empty part
| o  20863 - revset: raise ValueError when calling min or max on empty smartset
| o  20862 - revpair: smartset compatibility
| o  20861 - revsetbenchmark: add entry for ::rev::
:

我使用这个别名
[alias]
ll = log -l 12 --graph --template "{rev}{ifeq(branch,'default','',' {branch}')}{if(bookmarks,' {bookmarks}')}{if(tags,' {tags}')} - {desc|firstline}"

所以

$ hg ll
o  29100 @default tip - templater: add separate() template function
o  29099 - bookmarks: jettison bmstore's write() method per deprecation policy
o    29098 - merge with stable
|\
| o  29097 stable - deprecation: gate deprecation warning behind devel configurn
| |
| ~
o  29096 - crecord: update downarrowshiftevent() docstring, remove todo
o  29095 - crecord: remove things that don't happen in functions from their docs
o  29094 - crecord: remove skipfolded keyword argument from patchnode.previtem()
o  29093 - crecord: update a copy-pasted comment in downarrowshiftevent()
o  29092 - crecord: drop the version condition for amend
o  29091 - crecord: add/remove blank lines (coding style)
o  29090 - localrepo: jettison parents() method per deprecation policy (API)
o  29089 - revset: define _parsealias() in _aliasrules class
|
~

我认为它与Git非常相似

$ git log --graph --decorate --oneline --all
* d32f204 (origin/master, origin/HEAD) ; Remove instrumentation of tramp.el
* 4c7f329 ; Remove instrumentation of tramp-tests.el
* 51c816b Fix a problem of tramp-tests on hydra.
* 62d7aca Pacify byte-compiler in lisp/vc
*   9e6302c ; Merge from origin/emacs-25
|\  
* \   6d0703a Merge from origin/emacs-25
|\ \  
* | | 433d366 'text-quoting-style' now affects only ` and '
* | | 8939ae6 Revert "Fix spurious fontification of "for (; a * b;)" in CC Mod" 
* | | cfa59d6 ; Instrument tramp-tests.el
* | | c20cc09 Move "Recent messages" earlier in report-emacs-bug
* | | a88f22b Pacify byte compiler in tramp.el
* | |   c8b7a6a Merge from origin/emacs-25
|\ \ \  
* \ \ \   9418ab3 ; Merge from origin/emacs-25
|\ \ \ \  
* | | | | d6dac36 ; Instrument tramp.el
* | | | | a8231e0 CC Mode now uses the new :after-hook feature of define-deriv-e
* | | | | 608f2bd ; Instrument tramp-tests.el
* | | | | fd45b52 Fix the jit-lock-fontify-now test names
:

有关 graphshortengraphstyle 的文档资料在哪里可以找到? - Robert Siemer
这些仍然是[实验性的],因此可能需要浏览代码注释,请访问https://selenic.com/hg/log?rev=graphmod - santiagopim
Mercurial是否可以打印分支来自哪个远程库? - nonsensickle

3

没有直接的等价物(或者如果有的话,我想知道:-))。

部分原因是由于某些事情在Mercurial中不适用,其中任何给定提交都只存在于一个分支上,并且hg log默认显示所有分支上的所有提交。同样,不存在HEAD:有当前分支和当前提交,您可以将其命名为分支 . 或修订 .。它们的功能类似于HEAD,但不能是匿名分支。

无法单独查看远程,因为没有远程跟踪分支。如果你有任何传入的提交(hg incoming不打印任何内容),那么它已经在日志输出中了;否则,你必须运行hg pull,通常不带-u,才能获取它1,以便查看它。

当前提交会在hg log -G(也称为hg glog)输出中显示为@而不是o,因此这是您识别它的方式。

以下是我使用的内容(并不完全令人满意,我总是错过拓扑排序):

[alias]
# lga comes from
# http://jamie-wong.com/2012/07/11/my-mercurial-setup-and-workflow-at-khan-academy/
lga = glog --style ~/.hgstuff/map-cmdline.lg

截至目前,该 URL 仍在运行,但以下是我 map-cmdline.lg 文件的内容。请注意颜色是硬编码的;在我写这篇文章的时候,hg 没有命名的颜色词(可能仍然没有,我对最新的 hg 更新非常陌生):

changeset = '\033[0;31m{rev}:{node|short}:{phase} {branches}{bookmarks}{tags} \033[0;34m{author|person}\033[0m\n{desc|firstline|strip} \033[0;32m({date|age})\033[0m\n\n'
changeset_verbose = '\033[0;31m{rev}:{node}:{phase} \033[0;34m{author|person}\033[0m {desc|firstline|strip} \033[0;32m({date|age}) {branches}{bookmarks}{tags}\n\n'

start_branches = ' '
branch = '\033[0;32m{branch}\033[0m'

start_bookmarks = ' '
bookmark = '\033[0;32m[{bookmark}]\033[0m '
last_bookmark = '\033[0;31m[{bookmark}]\033[0m'

start_tags = ' '
tag = '\033[0;32m{tag}\033[0m, '
last_tag = '\033[0;32m{tag}\033[0m'

请注意,如果您试图将某些Hg工作流程与Git等效项进行比较,或者反之亦然,则存在轻微缺陷。 特别是,hg incoming 可以列出5个提交,然后 hg pull 会获取其中的12个提交,因为有人在两个步骤之间推送了7个更多的提交。 Git的独立fetch步骤和远程跟踪分支可以为您解决这个问题。 处理它的其他方法(出于其他原因我使用了一段时间)是保留一个本地的中间Mercurial仓库,用于从共享仓库进行拉取和推送。
也就是说,如果我们将repo U指定为上游共享仓库,我们在本地创建一个克隆I,然后在W中为执行工作而创建I的克隆。 然后我们更新I(使用hg pull -u),然后在W中查看hg incoming(和hg outgoing),以提高速度和一致性。最好直接从W推送到U,以避免不必要的提交阶段,但这会带来其他的问题。我从未找到真正令人满意的设置,并且当我在现场工作时放弃了中间仓库:这更多是为了处理缓慢的网络。

仅供参考 - Mercurial 今天已经 命名了颜色,但是:在Win-console中非常有限(至少在我的地图文件中),使用 label() ,以下是我2016年3月的样例:changeset = "{label('red',rev)} {label('blue', author|person)} {desc|firstline|strip} {label('green', date|age)} {label('yellow', branches)}{label('yellow',bookmarks)}{label('yellow', tags)}\n\n" - Lazy Badger
你从哪里得到这些 changeset_verbosestart_branches 的?它们分别在什么时候被激活? - Robert Siemer
@RobertSiemer:一般来说,X适用于log,而X_verbose适用于log -v。start_foo的名称是在任何foo名称之前发出的,但只有当有任何foo名称被发出时才会发出。我从各种地方获取了这些信息,不确定文档的质量如何,无论是过去还是现在。 - torek

2
第三次尝试,回复@santiagopim。
是的,Mercurial和Git使用非常不同的概念(没有远程跟踪,按默认传输所有分支的拉取|推送),但是:如果您想以更多的Git风格查看|使用Mercurial,并具有多个具有分歧历史的远程仓库,则可以:
  • 使用santiagopim的优秀模板(或根据torek的提示扩展为完整的样式)
  • 添加hgremotenamesremotebranches扩展程序(简而言之,为每个已拉取的远程名称添加描述性书签)
得到类似于Git日志的东西。

0

试试TortoiseHg吧。虽然不是命令行,但它可以满足需求。

它还会突出显示每个分支的提示(在Mercurial中称为“heads”)。仅显示分支名称无法突出显示它们,因为每个提交都有一个分支名称。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接