0

我需要使用命令行(没有 GUI 工具)来遍历 Mercurial 的历史,以获取单个行号,一直到历史的起点。例如,我在第 2 行将其用于 Git(使用git blame):

git blame -L2,2 --porcelain --incremental Filename.txt HEAD

d1b92f3a9e31ca3e3ee56f0965609314fc192f22 2 2 1  (<- the first 2 listed is the previous line number)
author Firstname Lastname
author-mail <author@domain.com>
author-time 1140197028
author-tz +0000
committer Firstname Lastname
committer-mail <author@domain.com>
committer-time 1140197028
committer-tz +0000
summary commit message here
previous 6bbaa283b326cde510ea3146a5fc6edd8956489a Filename.txt
filename Filename.txt

我需要以下信息:

  • 提交者/作者姓名
  • 前行号
  • 日期和时间
  • 前一个哈希

使用 git blame,我可以使用此信息并再次调用它以获取特定的哈希和前一行号,从而一直遍历该行的整个历史记录。

对于 Mercurial,我找到了hg annotate。我有以下内容:

hg annotate -unlcv -r tip Filename.txt | cat -n | sed -n 2,2p

2 Firstname Lastname <author@domain.com> 24741 7c36d9284795: 2: commit message here

所以这很好。我可以获得我需要的所有信息,包括最后一个哈希,但我不确定前一个行号。该行上面列出的前 2 个来自“cat”,但列出的第二个 2……是我应该遵循的前一个行号吗?我想绝对确保我正确地追溯了历史。

4

0 回答 0