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

爷,独闯天下 提交于 2019-11-29 09:14:31

问题


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?


回答1:


Don't worry about "the fear of two heads". Two heads is a very normal state. It's called anonymous branches, and it's one of the ways people do temporary branches in Mercurial.

Just commit, and then update to tip-1 and you're ready to go:

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

and away you 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 .

Don't fear heads -- they're what makes a DAG based VCS powerful.




回答2:


You can do this with the mq, attic or shelve extensions.




回答3:


  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. commands:

$hg tag Refactor
$cd ..
$hg clone Refactor Stable
$cd Stable
$hg revert -r REVISION_NUMBER

extra help:
http://hgbook.red-bean.com/
http://kiln.stackexchange.com/




回答4:


You can do it the simple way:

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

Your changes will now be stored in 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.




回答5:


In git you would do a 'stash'. According to This hg has 'shelve', but it requires an extension.



来源:https://stackoverflow.com/questions/6158419/hg-mercurial-any-way-to-set-aside-the-working-copy-for-later

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!