水银文件ID
有没有办法获取存储库中文件的不可变文件 ID?
我需要一个在文件重命名后仍然存在的标识符。因此,如果有文件 Test01.txt
并将其重命名为 Test02.txt
(使用 TortoiseHG 重命名菜单项或 hg rename
命令)。我想要一些与修订版 1 的 Test01.txt
和修订版 2 的 Test02.txt
相对应的 ID。
Is there any way to get an immutable file ID for a file in repository?
I need an identifier which will survive a file rename. So if there was file Test01.txt
and it was renamed to Test02.txt
(using TortoiseHG rename menu item or the hg rename
command). I want to have some ID which will correspond to Test01.txt
at revision 1 and Test02.txt
at revision 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mercurial 不会为文件提供任何 ID。这与其他一些系统不同,例如 Bazaar,其中每个文件(和目录)都有一个唯一的 ID,该 ID 在文件的整个生命周期中都跟随该 ID。
Mercurial 存储库中的结构如下:
因此,如果您在修订版 0 中添加
Test01.txt
,那么您将拥有一个像这样的链如果您现在重命名并创建一个新的提交,您将创建一个新的变更日志和清单条目,并为
Test02.txt
创建一个新文件日志:新的
Test02.txt
文件日志条目将引用Test01.txt
条目。这就是 Mercurial 跟踪重命名的方式:因此,您可以谈论的最佳“文件 ID”是原始文件日志中第一个条目的 ID。您可以使用
hg debugindex
来挖掘它:“nodeid”列为您提供
“linkrev”告诉您该版本的文件由变更集 0 引用。您可以使用
hg debugdata -c 0< 查找该变更日志条目中的数据/code>,但出于我们的目的,正常的
hg log
命令还包含信息:我们对清单 ID 感兴趣。您现在可以在正确的清单条目中查找数据:
文件名和文件日志 ID 之间确实有一个
NUL
字节,但它在您的终端中不可见。您现在拥有Test01.txt
文件第一个修订版的完整文件日志 ID。您还需要从
Test02.txt
转到Test01.txt
。您可以使用hg log --follow
和hg debugrename
来实现此目的:使用hg log
获取有关文件的修订版本,并使用hg debugrename
查看每个步骤中文件被重命名的内容。Mercurial does not give any ID to files. This is different from some other systems, such as Bazaar, where each file (and directory) has a unique ID that follows the file throughout it's life time.
The structure in a Mercurial repository is as follows:
So if you add
Test01.txt
in revision 0, then you'll have a chain like thisIf you now rename and make a new commit, you will create a new changelog and manifest entry, and create a new filelog for
Test02.txt
:The new
Test02.txt
filelog entry will reference theTest01.txt
entry. This is how Mercurial can keep track of renames:The best "file ID" you can talk about is therefore the ID of the first entry in the original file log. You can dig it out with
hg debugindex
:The "nodeid" column gives you the IDs for the revlog entries in the filelog for
Test01.txt
. Here we see that the first revision of the file has ID0936f74a5857
. This is just a short, 12 character prefix of the full 40 character SHA-1 hash. If you need the full hash, then read on...The "linkrev" tells you that this version of the file is referenced by changeset 0. You can lookup the data in that changelog entry with
hg debugdata -c 0
, but for our purposes the normalhg log
command also has the information:We're interested in the manifest ID. You can now look up the data in the correct manifest entry with:
There is really a
NUL
byte between the file name and the filelog ID, but it's not visible in your terminal. You now have the full filelog ID for the first revision of theTest01.txt
file.You also need to go from
Test02.txt
toTest01.txt
. You can usehg log --follow
andhg debugrename
for this: usehg log
to get the revisions concerning the file, and usehg debugrename
to see what the file was renamed from in each step.