给定一个文件,如何找出该版本在Mercurial存储库中是哪个版本? [英] Given a file, how to find out which revision in a mercurial repository this is?
问题描述
假定在hg
版本控制下有一个文件.我有该文件的特定版本,我想找出此文件在哪个版本中.
Assume that there is a file under hg
version control. I have a particular version of that file, and I would like to find out in which revision this file was in this version.
我怀疑有两种可能的方法.
I suspect that there are two possible ways to do this.
-
循环执行
hg update
并将文件与后续版本进行比较(sloooow,但应该可以使用).
Do
hg update
in a loop and diff the file against subsequent versions (sloooow, but should work).
在提交之前,使Mercurial将版本号放在文件第二行的a注释中.据我所读,
Make Mercurial put the rev number in a, say, comment in the second line of the file right before committing. From what I have read, a precommit
hook might be of use. Then I don't have to compare anything, just look at the file itself (I'm assuming no-one will change this, of course, but this is rather safe assumption in my case).
我的用例是用LaTeX编写的联合论文,有两位完全不了解版本控制的合著者,但我倾向于使用它(出于明显的原因).我们通过电子邮件进行通信,并且实际上有一个基于人的锁定系统(除非您向我发送下一个版本,好吗,我才能使用该文件").出现的唯一问题是,我将X版本发送给作者B进行校对,然后作者C向我发送了更正的版本Y,然后将其提交到我的存储库中,然后作者B发送了 his 更正Z (对于X版),我开始迷路了-但是我可以检查发送给B的电子邮件中的附件,而我只需要找出它的修订版本即可.
My use case is a joint paper, written in LaTeX, with two coauthors who have no idea about version control at all, but I prefer to use it (for obvious reasons). We communicate by email, and there's effectively a human-based lock system ("I will not work on this file until you send me the next version, ok?"). The only problem that arises is that I'm sending version X to author B to proofread, then author C sends me a corrected version Y and I commit it into my repo, then author B sends his corrections Z (to version X) and I'm starting to get lost-but I can check the attachment in the email sent to B, and I only need to find out which revision it is.
所以,我的问题是:以上两个想法中哪一个更好,或者也许还有另一个想法可以帮助我解决这个混乱局面?
So, my question is: which of the two ideas above would be better, or maybe there's yet another one to help me deal with this mess?
推荐答案
hg archive
是未来工作的好方法,但是我可以建议至少3种替代工作方式和1种修复方法供查找-带有更新的正确版本
hg archive
is good method for future work, but I can suggest at least 3 alternative work-styles and 1 fix for find-correct-version with updates
未来的工作
-
您可以为合著者使用单独的命名分支,并为合并结果使用默认命名分支,始终将合著者从其分支发送给他人,在得到更正后更新其分支(您将始终知道, /strong>发送)并将分支合并到默认
You can use separate named branches for co-authors and default for merged results, send co-author always head from his branch, update his branch after getting corrections (you'll always know, that you sent) and merge branches to default
一个分支,同事的版本标记为书签,您稍后将其移至下一个点
One branch, revision-of-coworker marked with bookmark, which you later move to next point
Mercurial关键字被以某种方式视为"不得已而为人的功能",但在您的情况下,这是显而易见且可用的解决方案:只需在文件中添加带有hash-id的关键字(默认扩展名而不是钩子-更容易,更可靠)
Mercurial keywords considered somehow as a "feature of last resort", but in your case it's obvious and usable solution: just add keyword with hash-id in file (defaul extension instead of hook - easier and more reliable)
当前状态
要查找带有文件源的变更集,可以尝试使用 bisect (示例),并在测试脚本中进行测试,例如文件的CRC(您需要未版本控制的CRC,请在历史记录中检查版本控制的文件)
For finding changeset with source of file, you can try to use bisect (example) and test in test-script, f.e, CRC of file (you have needed CRC of unversioned file, check versioned file across history)
这篇关于给定一个文件,如何找出该版本在Mercurial存储库中是哪个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!