Mercurial 命令等效

Mercurial commands equivalency

我试图找出以下 Mercurial 命令是否等效(如果目录已修改文件,则 id -i 输出中的附加 + 除外):hg id -ihg log -l1 --template "{node|short}"。是还是不是?

目的是潜在地加速一些不需要执行 id -i 的自动化,而是在 log 模板中使用 {node|short}。它们看起来是一样的,但我宁愿在我继续之前让其他人也看一下。

它们在某些条件下是等价的。当所有修订从 tip("newest")到 0 排序时,log -l 1 为您提供第一个修订。 hg id 告诉您当前签出的内容。因此,如果您还没有检查提示(假设您检查了一个分支组织的特定修订版),您将获得完全不同的输出:

ry4an@four:~/projects/mercurial-crew$ hg log -l1 --template "{node|short}\n"
7eda5bb9ec8f
ry4an@four:~/projects/mercurial-crew$ hg id -i
824f7b3545c1

但是,如果您已经签出 tip(并且您没有修改文件),那么它们是相同的(除了日志不提供没有 \n 的换行符):

ry4an@four:~/projects/mercurial-crew$ hg checkout tip
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
ry4an@four:~/projects/mercurial-crew$ hg id -i
7eda5bb9ec8f
ry4an@four:~/projects/mercurial-crew$ hg log -l1 --template "{node|short}\n"
7eda5bb9ec8f

它们不一样,因为 hg id 默认检查工作树,并且:

$ hg merge side
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg id -i
eb51a3480d0c+62e318575165+

如果您正在合并,工作树有两个父节点,hg id 打印它们两个。

同时,hg log 默认查看 current(糟糕,感谢 提示提交(而不是工作树); {node | short} 打印其 ID:

$ hg log -l1 --template '{node|short}'
eb51a3480d0c

另一方面,如果您不在合并过程中,则工作树只有一个父级。您还可以指定修订 .,这是当前提交...所以 在那种情况下,它们实际上是相同的。