如何使用 Mercurial 进行快速推送
本地存储库发生更改后,我使用 hg commit -m
提交,然后使用 hg Push
推送到我的服务器,然后在我的服务器中更新使用 hg update
的工作目录。
有更好的方法吗?
After a change in my local repo, I commit with hg commit -m <message>
, then I push to my server with hg push
, then in my server I update working dir with hg update
.
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所描述的前两个步骤:
是必需的,因为提交与 Mercurial 中的服务器(以及大多数其他 DVCS)完全分开。您可以编写一个提交后挂钩来在每次提交后执行推送,但不建议这样做,因为它会阻止您在提交期间和推送之前纠正简单的错误。
因为您尝试在“服务器”上执行更新,所以我假设您正在服务器上的存储库中执行代码版本。我之所以这么假设,是因为服务器通常只是充当您和您的开发人员访问的主存储库(并且还需要进行备份等......),并且不需要显式的
hg 更新.
假设您正在服务器上执行代码,您可以尝试使用以下命令替换推送和更新:
hg pull; -u
将从本地存储库执行拉取,然后自动更新。根据您的服务器配置,可能很难获取本地存储库的路径。
The first two steps you have described:
are required as per the fact that commits are kept completely separate from the server in Mercurial (and most other DVCS as well). You could write a post-commit hook to perform the push after each commit, but this is not advised because it prevents you from correcting simple mistakes during the commit and before the push.
Because you're trying to perform an update on 'the server' I'm assuming you are executing a version of the code in your repository on the server. I'm assuming this because typically the server would simply act as a master repository for you and your developers to access (and also to be subject to backups, etc..), and would not need the explicit
hg update
.Assuming you are executing code on the server, you can try and replace the push and the update with this command:
hg pull <path to development repo> -u
which will perform a pull from your local repo and then an automatic update. Depending on your server configuration, it might be difficult to get the path to your local repo.
对于问题的第一部分(即,提交时自动推送),您可以使用此答案中描述的技巧:每次提交都会自动推送。
如果您想自动更新工作目录,可以使用钩子来完成。将其添加到存储库的 hgrc 中(服务器目录中的
.hg/hgrc
):每次推送到此服务器时,这都会自动更新工作目录。此挂钩在 中进行了描述Mercurial 常见问题解答。
如果您使用这两种解决方案,下次执行
hg commit -m "message"
时,提交将自动推送到远程服务器,并且服务器上的工作目录将被更新。For the first part of the question (ie. automatically push when you do a commit), you can use the trick described in this answer : mercurial automatic push on every commit .
If you want to automatically update the working directory, you can do this with a hook. Add this in the hgrc of your repository (
.hg/hgrc
on your server directory) :This will automatically update the working directory every time a push is made to this server. This hook is described in the Mercurial FAQ.
If you use these 2 solutions, the next time you do
hg commit -m "message"
, the commit will be automatically pushed to the remote server and the working directory on the server will be updated.有一个名为 autosync 的扩展,您可能会觉得有用:
There is an extension called autosync you might find useful: