本文介绍了提交和推送单个文件同时保留其他修改的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Mercurial 还比较陌生,我的团队现在正在试用它作为 Subversion 的替代品.

I'm relatively new to Mercurial and my team is trying it out right now as a replacement for Subversion.

如何将单个文件提交并推送到另一个存储库,同时不提交工作目录中的其他修改(或至少不推送到另一个存储库)?

How can I commit and push a single file out to another repository while leaving other modifications in my working directory uncommitted (or at least not pushed to the other repository)?

我们在数据库迁移时会发生这种情况.我们希望将迁移提交到源代码控制,以便 DBA 在我们进行代码修改以进行数据库迁移时可以查看和编辑它.更改尚未准备就绪,因此我们不想将它们全部推出.

This happens for us with database migrations. We want to commit the migration to source control so a DBA can view and edit it while we're working on the code modifications to go along with that database migration. The changes aren't yet ready to go so we don't want to push all of them out.

在颠覆中,我只会做:

svn add my_migration.sql
# commit only the migration, but not the other files I'm working on
svn commit -m "migration notes" my_mygration.sql

并继续在本地工作.

这对 mercurial 不起作用,因为当我将它推送到另一个存储库时,如果我没有将其更改,它希望我将它们拉下来,合并它们并提交合并到存储库.合并后提交不允许您省略文件,因此它会强制您提交本地存储库中的所有内容.

This doesn't work with mercurial as when I'm pushing it out to the other repository, if there are changes to it that I haven't pulled down, it wants me to pull them down, merge them, and commit that merge to the repository. Commits after a merge don't allow you to omit files so it forces you to commit everything in your local repository.

我能想到的最简单的事情是将文件提交到我的本地存储库,克隆我的本地存储库,从实际存储库中获取任何新更改,合并它们并提交该合并,然后他们将我的更改推送出去.

The easiest thing that I can figure out is to commit the file to my local repository, clone my local repository, fetch any new changes from the actual repository, merge them and commit that merge, and them push my changes out.

hg add my_migration.sql
hg commit -m "migration notes" my_migration.sql
cd ..
hg clone project project-clone
cd project-clone
hg fetch http://hg/project
hg push  http://hg/project

这有效,但感觉好像我错过了一些更简单的东西,某种方式告诉 mercurial 忽略我工作目录中已有的文件,只需进行合并并发送文件即可.我怀疑 mercurial 队列可以做到这一点,但我还没有完全理解 mq.

This works, but it feels like I'm missing something easier, some way to tell mercurial to ignore the files already in my working directory, just do the merge and send the files along. I suspect mercurial queues can do this, but I don't fully grok mq yet.

推荐答案

有一个 Mercurial 功能可以实现搁置和取消搁置命令,它为您提供了一种交互式方式来指定要存储到以后的更改:搁置.

There's a Mercurial feature that implements shelve and unshelve commands, which give you an interactive way to specify changes to store away until a later time: Shelve.

然后您可以hg shelvehg unshelve 暂时存储更改.它让您可以在补丁大块"级别工作,以挑选和选择要搁置的项目.它似乎没有搁置列出的要添加的文件,只有已在存储库中进行修改的文件.

Then you can hg shelve and hg unshelve to temporarily store changes away. It lets you work at the "patch hunk" level to pick and choose the items to shelve away. It didn't appear to shelve a file had listed for adding, only files already in the repo with modifications.

它作为扩展"包含在 Mercurial 中,这意味着您必须在 hg 配置文件中启用它.

It is included with Mercurial as an "extension" which just means you have to enable it in your hg config file.

真正旧版本的 Mercurial 的注意事项(在包括搁置之前 - 这不再需要):

Notes for really old versions of Mercurial (before shelve was included -- this is no longer necessary):

我在谷歌搜索中没有看到任何很好的安装说明,所以这里是我用来让它工作的组合:

I didn't see any great install instructions with some googling, so here is the combined stuff I used to get it working:

获取:

hg clone http://freehg.org/u/tksoh/hgshelve/ hgshelve

项目中唯一的文件(当前)是 hgshelve.py 文件.

The only file (currently) in the project is the hgshelve.py file.

修改您的 ~/.hgrc 以添加搁置扩展名,指向您克隆存储库的位置:

Modify your ~/.hgrc to add the shelve extension, pointing to where you cloned the repo:

[extensions]
hgshelve=/Users/ted/Documents/workspace/hgshelve/hgshelve.py

这篇关于提交和推送单个文件同时保留其他修改的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:09