我可以在 Mercurial 中将文件标记为“从不提交此文件”吗?
在我们的应用程序中,用户可以使用工具栏在页面之间导航,默认情况下显示第 1 页。我正在修改第 3a 页,该页只能通过单击几次工具栏来访问。在调试过程中这样做很烦人,所以在 main.cpp 中我将默认值设置为 Page 3a,但我绝对不想签入它。但是,Mercurial 不断告诉我 main.cpp 被修改了(当然),这会干扰诸如合并之类的事情。
我想将 main.cpp 移动到 Mercurial 中的一个特殊列表中,基本上是“是的,我知道这个文件被修改了,不用担心”。请注意,Shelf 扩展并不是我想要的,因为 main.cpp 将恢复到其原始状态。我也不想“忘记”该文件。有人有解决方案吗?
(mods:请随意编辑这个问题以使其更加简洁)
In our app, the user can navigate between pages using the toolbar, and Page 1 is shown by default. I'm modifying Page 3a, which is only accessible through a couple of toolbar clicks. This is annoying to do during debugging, so in main.cpp I've set the default to be Page 3a, but I definitely do not want to check this in. However, Mercurial is constantly telling me that main.cpp is modified (of course), and this interferes with things like merges.
I would like to move main.cpp into a special list within Mercurial that is basically, "yes, I know this file is modified, don't worry about it". Note that the Shelf extension isn't quite what I want, because main.cpp will be reverted back to its original state. I also don't want to "forget" the file. Does anyone have a solution for this?
(mods: feel free to edit this question to be more concise)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果它更短,我会将其添加为 pyfunc 答案的注释,因为它只是添加一些信息。
显然有两个问题:
要添加到 (1) 的提交排除建议,如果您可以使用 TortoiseHg,它会提供一个提交排除列表,而无需默认部分的缺点,并且无需记住是否需要在此特定项目上使用别名。您可以在此处了解我的使用经验。
(2) 没有答案。虽然搁置需要几个步骤,但您将不得不投入一些工作,因为 Mercurial 将无法拉动本地更改,就这么简单。我会推荐 mq,因为 Tortoise 提供了与提交对话框的良好集成,但它实际上并不比单文件更改情况下的搁置简单。
不过,使用 shelve 或 mq 确实并不难,所以我不会太担心。
If this were shorter, I would have added it as a comment to pyfunc's answer, since it's just adding a bit of info.
There are two issues, apparently:
To add to the commit exclude suggestion for (1), if you can use TortoiseHg, it offers a commit exclude list without the drawback of the defaults section and without needing to remember whether you need to use an alias on this particular project. You can read about my experience with it here.
There is no answer for (2). While shelve takes a couple steps, you're going to have to put in some work because Mercurial will fail to pull with local changes, it's that simple. I would recommend mq since Tortoise provides nice integration with the commit dialog, but it's really not any simpler than shelve in the one-file-changed case.
It's really not hard to use shelve or mq, though, so I wouldn't worry too much about it.
没有任何扩展允许您忽略 Mercurial 已跟踪的文件。
然而,您可以遵循的方法很少。
正如 Ry4an 建议,阻止包含该文件的提交,然后执行显式
另一种优雅的方法是告诉提交方法在提交文件时忽略某些类型的文件。
我更喜欢这种方法。
例子:
There are no extensions that allows you to ignore a file that is already tracked by Mercurial.
How ever, there are few approaches which you can follow.
As Ry4an suggest, block commits that include the file and then do a explicit
Another elegant approach is to tell the commit method to ignore certain types of file while committing files.
I like this approach better.
Example:
这实际上是一种相当常见的使用模式。对于仅一个文件,
-X
选项或根据需要搁置和取消搁置可能是最简单的方法,但与 DVCS 一样,更通用的解决方案涉及创建另一个分支。一个例子(对于 bzr,但原则适用)可以在 找到在这里。本质上,您从镜像上游分支的公共分支开始。从那里,您可以分支出一个“本地更改”分支,您可以在其中对 main.cpp 进行更改。从该“本地更改”分支中,您可以创建功能分支,您可以在其中进行正常的日常工作,并正常提交。
当您准备好共享更改时,您可以将它们选回您的第一个分支,从而获得刚刚所做的更改,而无需对 main.cpp 进行本地更改。使用此方法,您甚至可以对 main.cpp 进行公开修复,而无需检查本地调试黑客。缺点是拉取和合并会产生一些额外的复杂性,因为它们必须首先经过上游和本地更改分支才能保持樱桃采摘清洁。
This is actually a fairly common usage pattern. For just one file, either the
-X
option or shelving and unshelving as needed is probably the simplest method, but as usual for DVCS, the more general solution involves creating another branch. An example of that (for bzr, but the principles apply) is found here.Essentially, you start with your public branch that mirrors the upstream branch. From there, you branch off a "local changes" branch, which is where you make the change to main.cpp. From that "local changes" branch, you create your feature branch, which is where you do your normal daily work, committing as normal.
When you're ready to share your changes, you cherry pick them back into your first branch, thereby getting the changes you just made without the local changes to main.cpp. Using this method, you can even make public fixes to main.cpp without your local debug hack getting checked in. The downside is some extra complexity on pulls and merges, as they have to go through the upstream and local changes branches first in order to keep the cherry pick clean.
正如克里斯在评论中指出的那样,快速而肮脏的方法是使用我在另一个问题中建议的机制。更好的方法是使用一个提交钩子来阻止包含该文件的提交:
您仍然必须记住不要在提交行中包含 main.cpp,但是当您忘记提交时将拒绝提交。
As Chris pointed out in the comments the quick and dirty way to do this is using the mechanism I suggested in another question. The better way to do it is a commit hook that prevents commits including that file:
You still have to remember not to include main.cpp in your commit line, but when you forget the commit will refuse to commit.