Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Version control 什么';提交和推送单个文件而不进行其他修改的最简单方法是什么?_Version Control_Mercurial_Merge_Push - Fatal编程技术网

Version control 什么';提交和推送单个文件而不进行其他修改的最简单方法是什么?

Version control 什么';提交和推送单个文件而不进行其他修改的最简单方法是什么?,version-control,mercurial,merge,push,Version Control,Mercurial,Merge,Push,我对Mercurial比较陌生,我的团队现在正在尝试用它来替代Subversion 如何提交一个文件并将其推送到另一个存储库,同时保持工作目录中的其他修改未提交(或至少未推送到另一个存储库) 对于我们来说,数据库迁移就是这样。我们希望将迁移提交到源代码管理,以便DBA可以在我们进行代码修改时查看和编辑它,以配合数据库迁移。这些变化还没有准备好,所以我们不想把它们全部推出去 在subversion中,我只需执行以下操作: svn add my_migration.sql # commit on

我对Mercurial比较陌生,我的团队现在正在尝试用它来替代Subversion

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

对于我们来说,数据库迁移就是这样。我们希望将迁移提交到源代码管理,以便DBA可以在我们进行代码修改时查看和编辑它,以配合数据库迁移。这些变化还没有准备好,所以我们不想把它们全部推出去

在subversion中,我只需执行以下操作:

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不起作用,因为当我将它推出到另一个存储库时,如果对它进行了更改,但我没有拉下来,它希望我拉下来,合并它们,并将合并提交到存储库。合并后提交不允许您忽略文件,因此它会强制您提交本地存储库中的所有内容

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

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。

mercurial的一个功能是实现搁置和取消搁置命令,这为您提供了一种交互方式,可以指定要保存到以后的更改:

然后您可以
hg shelve
hg unshelve
临时存储更改。它可以让你在“补丁帅哥”级别挑选要搁置的物品。它似乎没有搁置已列出的文件以供添加,只有已在回购协议中修改的文件

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


Mercurial非常旧版本的注释(在包含shelve之前——不再需要):

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

通过以下方式获得:

hg clone http://freehg.org/u/tksoh/hgshelve/ hgshelve
项目中唯一的文件(当前)是hgshelve.py文件

修改~/.hgrc以添加搁置扩展,指向您克隆回购的位置:

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

如果您不想依赖扩展,另一种选择是在本地保留上游存储库的克隆,仅用于此类集成任务


在您的示例中,您可以简单地将更改拉入/合并到集成/上游存储库中,并将其直接推送到远程服务器。

tl;dr:我最初的解释看起来很复杂,但我希望它能充分解释如何使用补丁队列。以下是简短的版本:

$ hg qnew -m "migration notes" -f migration my_migration.sql
$ hg qnew -f working-code
# make some changes to your code
$ hg qrefresh # update the patch with the changes you just made
$ hg qfinish -a # turn all the applied patches into normal hg commits

反复无常的队列使这类事情变得轻而易举,并且使更复杂的变更集操作成为可能。这是值得学习的

在这种情况下,首先您可能希望在下拉更改之前保存当前目录中的内容:

# create a patch called migration containing your migration
$ hg qnew -m "migration notes" -f migration.patch my_migration.sql
$ hg qseries -v # the current state of the patch queue, A means applied
0 A migration.patch
$ hg qnew -f working-code.patch # put the rest of the code in a patch
$ hg qseries -v
0 A migration.patch
1 A working-code.patch
现在让我们对工作代码做一些额外的工作。我将继续做
qseries
只是为了明确起见,但是一旦你建立了补丁队列的心智模型,你就不必一直看列表了

$ hg qtop # show the patch we're currently editing
working-code.patch
$ ...hack, hack, hack...
$ hg diff # show the changes that have not been incorporated into the patch
blah, blah
$ hg qrefresh # update the patch with the changes you just made
$ hg qdiff # show the top patch's diff
因为您的所有工作现在都保存在修补程序队列中,所以您可以取消应用这些更改,并在拉入远程更改后恢复这些更改。通常要取消应用所有补丁,只需执行
hg qpop-a
。为了显示对补丁队列的影响,我将一次弹出一个

$ hg qpop # unapply the top patch, U means unapplied
$ hg qseries -v
0 A migration.patch
1 U working-code.patch
$ hg qtop
migration.patch
$ hg qpop
$ hg qseries -v
0 U migration.patch
1 U working-code.patch
此时,您的目录中似乎没有任何更改。执行
hg fetch
。现在,您可以重新启动补丁队列更改,并在出现任何冲突时合并它们。这在概念上有点类似于git的rebase

$ hg qpush # put the first patch back on
$ hg qseries -v
0 A migration.patch
1 U working-code.patch
$ hg qfinish -a # turn all the applied patches into normal hg commits
$ hg qseries -v
0 U working-code.patch
$ hg out
migration.patch commit info... blah, blah
$ hg push # push out your changes
此时,您已经完成了迁移,同时保留了其他本地更改。您的其他更改位于队列中的修补程序中。我的大部分个人开发都是使用补丁队列来帮助我更好地组织更改。如果你想摆脱补丁队列,回到一个正常的样式,你必须导出你的更改,并在“正常”mercurial中重新导入它们

$ hg qpush
$ hg qseries -v
0 A working-code.patch
$ hg export qtip > temp.diff
$ rm -r .hg/patches # get rid of mq from the repository entirely
$ hg import --no-commit temp.diff # apply the changes to the working directory
$ rm temp.diff


我非常沉迷于开发补丁队列,
mq
是最好的实现之一。同时进行多个更改的能力确实提高了提交的集中度和干净度。这需要一段时间来适应,但它与DVCS工作流非常配合。

自从我最初提出这个问题以来,已经快2年了。我现在会做不同的事情(正如我在上面问题的评论中提到的)。我现在要做的是将我的更改提交到本地repo中的一个文件(您可以使用hg记录扩展名仅提交文件的一部分):

然后就推出去

hg push
如果因为我需要首先合并的回购协议的其他更改而发生冲突,我会更新到父版本(见“hg parents-r”。如果你不知道它是什么),在那里提交我的其他更改,因此我有两个头。然后恢复到原始的单文件提交,并将更改拉入/合并到该版本中。然后用

hg push --rev .
仅推出单个文件和该修订的合并。然后你可以合并你在本地得到的两个头


这种方式消除了mq内容和被拒绝的帅哥的可能性,并通过源代码控制跟踪所有内容。如果您以后决定不需要修订,也可以将其“删除”。

我通常使用的是提交单个文件:

 hg commit -m "commit message" filename
以防洛杉矶
 hg commit -m "commit message" filename
hg diff > changes.patch
hg revert --all
hg pull -u
hg merge
hg commit -m "local merge"
hg import --no-commit changes.patch