如何在 Mercurial 中重命名目录并继续跟踪所有文件更改

发布于 2024-09-14 23:30:24 字数 787 浏览 4 评论 0原文

我决定将我的 home/hobby Python 包中的一些目录重命名(docdocstesttestsutilutils),因为现在我已经考虑了更多,我认为新名称更合适。我现在的总体想法是,如果容器以其内容命名,那么它们的名称应该是复数名词。

现在我已经准备好进行下一次 hg 提交,我想知道如何告诉 Mercurial 这些目录名称更改。总的来说,我对 RCS 软件很陌生,并且只使用 Mercurial 几个月。当我运行 hg status 时,它显示这些目录中的所有文件都被删除和添加,所以我担心如果我只执行 hg addremove 我会丢失所有这些目录中的文件的更改历史记录,或者至少更改历史记录将变得支离破碎且无法追踪。我遇到过 hg rename 命令,但文档仅讨论其对单个文件的使用,而不是目录。

进一步阅读 Bryan O'Sullivan 的“权威指南”后,似乎 rename 可以引用目录。

所以这就是我决定尝试的方法:

hg rename --after doc docs
hg rename --after test tests
hg rename --after util utils
hg status
hg addremove

谁能告诉我这是否是 Mercurial 中重命名目录的可接受且首选的方法,如果不是,我应该怎么做。

I decided to rename some directories in my home/hobby Python package (doc to docs, test to tests, util to utils) because, now that I've thought more about it, I think the new names are more appropriate. My general thinking now is that if containers are named after their contents their names should be plural nouns.

Now that I'm ready for my next hg commit I'm wondering how to tell Mercurial about these directory name changes. I am new to RCS software in general and have only been using Mercurial for a couple months. When I run hg status it shows all the the files in these directories being removed and added, so I'm afraid if I just do a hg addremove I will loose all the change history for the files in these directories, or at the very least the change history will become fragmented and untraceable. I've come across the hg rename command, but the docs only discuss its use for individual files, not directories.

After further reading in Bryan O'Sullivan's 'Definitive Guide' it appears that maybe rename can refer to directories.

So here's what I've decided to try:

hg rename --after doc docs
hg rename --after test tests
hg rename --after util utils
hg status
hg addremove

Can anyone tell me if this is the accepted and preferred method for renaming directories in Mercurial, and if not, how should I do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笔落惊风雨 2024-09-21 23:30:24

由于您已经重命名了目录,因此完全可以。 (如果您让 Mercurial 为您重命名它们,那么您可以节省手动步骤:hg rename doc docs 等,而不是自己执行此操作然后让 Mercurial 了解)。

如果您没有任何其他文件要签入,则 hg addremove 是多余的。查看 hg stat 的输出,您应该只会看到以“R”开头的行(对于 doc/*test/* 和 < code>util/*) 和 'A'(用于 docs/* 等)

最后,不要忘记提交更改。

编辑:忘了说...使用hg log --follow来跟踪重命名过程中的更改。

Since you've already renamed the directories, this is perfectly OK. (It would have saved you a manual step if you'd let Mercurial rename them for you: hg rename doc docs, etc. instead of doing it yourself then letting Mercurial know about it).

If you don't have any other files to check in, the hg addremove is superfluous. Look in the output of hg stat and you should only see lines beginning with 'R' (for doc/*, test/* and util/*) and 'A' (for docs/*, etc.)

Finally, don't forget to commit the changes.

EDIT: Forgot to say... use hg log --follow to track changes across the rename.

那小子欠揍 2024-09-21 23:30:24

Mercurial 没有目录的概念;它将所有内容(文件和目录)视为文件。另外,我通常从不手动重命名文件或目录;我只是用

hg 重命名旧名称新名称

我建议你也这样做。

Mercurial 提供重命名跟踪功能,这意味着 Mercurial 可以跟踪已重命名的文件的完整历史记录。如果你手动重命名它,这是不可能的。

但是,由于您已经手动重命名它们,因此需要使用 --follow 参数和 hg log 来跟踪历史记录中的文件更改。

就我个人而言,我只会使用 hg rename,它应该是首选方法。

Mercurial has no concept of directories; it treats everything (files and directories) as files. Also, I usually never rename files or directories manually; I just use

hg rename old-name new-name

I suggest you do that too.

Mercurial offers a rename-tracking feature, which means that mercurial can trace the complete history of a file which has been renamed. If you manually rename this, its not possible.

However, as you have already renamed them manually, you need to use the --follow argument along with hg log to track the file changes through the history.

Personally I'd just go with hg rename and it should be the preferred method.

半城柳色半声笛 2024-09-21 23:30:24

使用 --after 而不是使用 hg 重命名的原因之一是,如果您使用的重构工具不仅可以重命名,例如还可以修复引用。

One reason to use --after instead of renaming with hg is if you are using a refactoring tool that does more than just rename e.g. also fixes references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文