“bzr 未提交” Mercurial 中的等效项?
Bazaar 有一个很棒的 uncommit
命令,它可以简单地撤消最后一次提交。 Mercurial 中有类似的东西吗?
编辑:Bazaar 的取消提交命令不会修改文件 - 它会删除最后一次提交和关联的数据(例如,当您发现提交消息中有拼写错误或文件不正确时,这很有用) t 补充说应该是)。
例如:
$ bzr ci -m "Fixed a proooblem" <-- problem is misspelt
$ bzr uncommit
...
$ bzr ci -m "Fixed a problem" <-- Exactly as if the first commit was correct.
Bazaar has a wonderful uncommit
command, which simply undoes the last commit. Is there any equivalent in Mercurial?
Edit: Bazaar's uncommit command does not modify files – it removes the last commit and associated data (useful, for example, when you notice too late that there is a typo in a commit message or a file wasn't added that should have been).
For example:
$ bzr ci -m "Fixed a proooblem" <-- problem is misspelt
$ bzr uncommit
...
$ bzr ci -m "Fixed a problem" <-- Exactly as if the first commit was correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要
hg rollback
命令,但如果您需要,请参阅下文使用 Mercurial 2.2 或更高版本。回滚命令将从存储库中删除最后一个事务。 提交是一个事务,因此您可以将其用作
回滚后,文件将再次被视为已修改,这意味着第二次提交将存储与第一次相同的更改,但具有更好的提交消息。
注意:
hg rollback
比简单的“取消提交”功能更强大,如果您不小心,您可以使用它来丢弃工作。 要丢弃提交,您现在已经丢失了最后一次提交,并且由于您将工作副本更新为其他版本,所以该提交中的更改消失了。 因此,如果您确定
hg commit
确实是在工作副本上操作的最后一个命令,则应该仅使用hg rollback
撤消提交。另外,如果您没有在命令行上给出提交消息,那么您不能只按向上箭头两次来在回滚后重做提交。 但是,Mercurial 1.5 及更高版本会将您的最后提交消息保存在
.hg/last-message.txt
中,以便您在回滚后始终可以再次找到它。Mercurial 2.2 为
hg commit
提供了一个新的--amend
标志。 这让您可以用新的更改来修改最后一次提交。 它只是将hg status
列出的更改合并到父提交中,就好像您已回滚并再次提交一样。You want the
hg rollback
command, but see below if you're using Mercurial 2.2 or later.The rollback command will remove the last transaction from your repository. A commit is a transaction, so you can use this as
After the rollback the files will again be seen as modified, and this means that the second commit will store the same changes as the first, but with a better commit message.
Beware:
hg rollback
is more powerful than a simple "uncommit" function and you can use it to throw away work if you are not careful. To throw away a commit doYou've now lost the last commit you made and since you updated the working copy to some other revision, the changes in that commit are gone. So you should only use
hg rollback
to undo a commit if you're certain thathg commit
really was the last command that operated on the working copy.Also, if you have not given the commit message on the command line, then you cannot just press up-arrow twice to redo the commit after a rollback. However, Mercurial 1.5 and later will save your last commit message in
.hg/last-message.txt
so that you can always find it again after a rollback.Mercurial 2.2 has a new
--amend
flag forhg commit
. This let's you amend the last commit with new changes. It simply incorporates the changes listed byhg status
into the parent commit, as if you had rolled back and committed again.也许
hg backout Tip
? 我推荐 http://hgbook.red-bean.com/read /finding-and-fixing-mistakes.html 有关hg backout
的所有详细信息,它与hg revert
有何不同,以及许多相关主题,但如果我了解uncommit
的作用,它看起来确实与hg backout Tip
完全相同。编辑:在评论中,你现在已经澄清你想要“删除历史记录”——这很难(除非你抽奖速度非常快,也许;-)......再次按照红豆书:
所以如果你只是想尝试“让它消失”(而且你很幸运它还没有被推或拉到其他地方),那么
hg rollback
可能是一个更好的方法!Maybe
hg backout tip
? I recommend http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html for all details abouthg backout
, how it differs fromhg revert
, and many related topics, but if I undestand whatuncommit
does, it does seem exactly equivalent tohg backout tip
.Edit: in a comment you've now clarified you want to "delete history" -- that's hard (unless you're VERY fast on the draw, maybe;-)... per the red-bean book again:
So if you just want to try to "make it disappear" (and you're lucky enough that it hasn't yet been pushed or pulled elsewhere), then
hg rollback
may be a better approach!“hg revert”不是这样做吗?
Doesn't "hg revert" do that?
从阅读评论来看,您似乎想要一种简单地删除提交记录而不撤消对文件的更改的方法。 在 Mercurial 中,没有自动方法来执行此操作。
hg revert
与您所能得到的最接近。但是,您可以通过几个手动步骤来完成此操作。 当您调用
hg revert
时,其默认行为是获取要还原的变更集中的文件并将它们重命名为filename.ext.orig
,其中ext< /code> 是文件的原始扩展名。 然后恢复的版本将采用原始文件名。 因此,您可以运行
hg revert
,删除原始名称的文件,并从备份文件的名称中删除.orig
。 然后使用更正的日志消息重新提交。 只是不要对除提示之外的任何修订执行此操作,因为您可能会获得大量更改的文件,并忘记哪些文件属于哪个变更集。如果您已经将变更集推送到远程存储库,我也不建议您这样做。 仅当一切仍然只是本地时才执行此操作。
如果您需要进一步解释,请告诉我。 我有时不得不这样做,所以我熟悉这个过程。
From reading the comments, it seems that you want a way to simply do away with the record of the commit without undoing the changes to the file. In Mercurial, there is no automated way of doing this.
hg revert
is as close as you're going to get.However, you could do this with a couple manual steps. When you invoke
hg revert
, its default behavior is to take the files in the changeset you are reverting and rename them asfilename.ext.orig
, whereext
is the original extension of the file. The reverted versions then take on the original filename. So what you could do is runhg revert
, delete the files with the original names, and remove.orig
from the backup files' names. Then re-commit with your corrected log message. Just don't do this with any revision other than the tip because you'll probably get a lot of changed files and forget which ones belonged in which changeset.I also would not recommend doing this if you've already pushed your changesets out to a remote repo. Only do this if everything is still only local.
Let me know if you need further explanation. I've had to do this on occasion, so I'm familiar with the process.
还有来自“mq”扩展的“hg strip”命令。 它几乎与“bzr uncommit”完全相同。 但请注意,当您之前将错误的提交推送到另一个存储库时,它将使用最近的拉取重新创建它。
There is also the "hg strip" command from the "mq" extension. It is almost exact equivalent of "bzr uncommit". Beware though, when you pushed your errant commit earlier to another repository, it will be recreated with the nearest pull from it.