简体   繁体   English

Hg (Mercurial):有什么方法可以“搁置”工作副本供以后使用?

[英]Hg (Mercurial): any way to “set aside” the working copy for later?

Scenario: After your last commit, you decided to do some extensive refactoring of the codebase.场景:在您最后一次提交之后,您决定对代码库进行一些广泛的重构。 After a time, you realize it is taking longer than expected, and you'd really rather put off the refactoring for another time, and work on more pressing tasks.一段时间后,您意识到它花费的时间比预期的要长,您真的宁愿将重构推迟一次,并处理更紧迫的任务。 But you don't want to lose all of the refactoring work you've done so far.但是您不想丢失迄今为止所做的所有重构工作。

So, is there a way to "archive" or "branch" the working copy (essentially, set it aside but keep it in the repository for later access), and then revert to the last good commit and resume from there, without fear of creating multiple heads or getting the two mixed up?那么,有没有办法“存档”或“分支”工作副本(本质上,将其放在一边,但将其保存在存储库中以供以后访问),然后恢复到最后一次良好的提交并从那里恢复,而不必担心创建多个头还是将两者混淆?

Don't worry about "the fear of two heads".不要担心“两个头的恐惧”。 Two heads is a very normal state.两个头是很正常的state。 It's called anonymous branches, and it's one of the ways people do temporary branches in Mercurial.它被称为匿名分支,它是人们在 Mercurial 中做临时分支的方式之一。

Just commit, and then update to tip-1 and you're ready to go:只需提交,然后更新到tip-1,您就可以准备好go:

hg commit -m "working on XXX"
hg update -r "tip-1"

and away you go.离开你go。 If you want to drop a bookmark (less permanent than a tag) on that head you can, but there's no need to worry about it.如果你想在那个头上放一个书签(不如标签永久),你可以,但不必担心。

You can always push one head without pushing another using hg push -r HEAD where that can even be hg push -r.您总是可以使用hg push -r HEAD推一个头而不推另一个头,其中甚至可以是hg push -r.

Don't fear heads -- they're what makes a DAG based VCS powerful.不要害怕头脑——他们是基于 DAG 的 VCS 强大的原因。

You can do this with the mq, attic or shelve extensions.您可以使用 mq、attic 或 shelve 扩展来做到这一点。

  1. Assign a tag to your refactor revision为重构修订分配标签
  2. Commit the tag提交标签
  3. Clone the repository again再次克隆存储库
  4. Revert to the stable version恢复到稳定版本
  5. Work from the stable version从稳定版本开始工作
  6. Don't worry about multiple heads, you can easily merge later不用担心多头,以后可以轻松合并

Since mercurial uses hard links, you can keep both repositories on your local machine with minimal space used.由于 mercurial 使用硬链接,因此您可以将两个存储库保留在本地计算机上,并且使用最少的空间。 commands:命令:

$hg tag Refactor $hg 标签重构
$cd.. $cd..
$hg clone Refactor Stable $hg clone 重构稳定版
$cd Stable $cd 稳定的
$hg revert -r REVISION_NUMBER $hg 还原 -r REVISION_NUMBER

extra help:额外帮助:
http://hgbook.red-bean.com/ http://hgbook.red-bean.com/
http://kiln.stackexchange.com/ http://kiln.stackexchange.com/

You can do it the simple way:你可以用简单的方法做到这一点:

$ hg diff -g > tmp
$ hg revert --all

Your changes will now be stored in tmp .您的更改现在将存储在tmp中。 You can restore them with您可以使用

$ hg patch --no-commit tmp

and you'll be back where you were.你会回到原来的地方。 There are extensions like shelve that automates the above for you.有像搁置这样的扩展可以为您自动执行上述操作。

In git you would do a 'stash'.在 git 中,你会做一个“藏匿”。 According to This hg has 'shelve', but it requires an extension.根据This hg 有“搁置”,但它需要扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM