提交和推送单个文件同时不进行其他修改的最简单方法是什么? [英] What's the easiest way to commit and push a single file while leaving other modifications alone?

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

问题描述

我对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.

在Subversion中,我只是要做:

In subversion, I'd simply do:

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.

我能想到的最简单的方法是将文件提交到本地存储库,克隆本地存储库,从实际存储库中获取任何新更改,合并并提交合并,然后将我的更改推出. /p>

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆