“bzr 未提交” Mercurial 中的等效项?

发布于 2024-07-22 07:49:39 字数 394 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

め七分饶幸 2024-07-29 07:49:39

您需要 hg rollback 命令,但如果您需要,请参阅下文使用 Mercurial 2.2 或更高版本。

回滚命令将从存储库中删除最后一个事务。 提交是一个事务,因此您可以将其用作

% hg commit -m 'My elaburate bugfix.' foo.c foo.h
% hg rollback
% hg commit -m 'My elaborate bugfix.' foo.c foo.h

回滚后,文件将再次被视为已修改,这意味着第二次提交将存储与第一次相同的更改,但具有更好的提交消息。

注意: hg rollback 比简单的“取消提交”功能更强大,如果您不小心,您可以使用它来丢弃工作。 要丢弃提交,

$ hg commit -m 'My big and very difficult bugfix'
$ hg pull --update
$ 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

% hg commit -m 'My elaburate bugfix.' foo.c foo.h
% hg rollback
% hg commit -m 'My elaborate bugfix.' foo.c foo.h

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 do

$ hg commit -m 'My big and very difficult bugfix'
$ hg pull --update
$ hg rollback

You'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 that hg 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 for hg commit. This let's you amend the last commit with new changes. It simply incorporates the changes listed by hg status into the parent commit, as if you had rolled back and committed again.

攒一口袋星星 2024-07-29 07:49:39

也许hg backout Tip? 我推荐 http://hgbook.red-bean.com/read /finding-and-fixing-mistakes.html 有关 hg backout 的所有详细信息,它与 hg revert 有何不同,以及许多相关主题,但如果我了解 uncommit 的作用,它看起来确实与 hg backout Tip 完全相同。

编辑:在评论中,你现在已经澄清你想要“删除历史记录”——这很难(除非你抽奖速度非常快,也许;-)......再次按照红豆书:

由于 Mercurial 将历史视为累积性(每个更改都建立在之前的所有更改之上),因此您通常不能让灾难性的更改消失。 一个例外是当您刚刚提交更改,并且尚未将其推送或拉入另一个存储库时。 这时您就可以安全地使用 hg rollback 命令

所以如果你只是想尝试“让它消失”(而且你很幸运它还没有被推或拉到其他地方),那么hg rollback可能是一个更好的方法!

Maybe hg backout tip? I recommend http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html for all details about hg backout, how it differs from hg revert, and many related topics, but if I undestand what uncommit does, it does seem exactly equivalent to hg 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:

Since Mercurial treats history as accumulative—every change builds on top of all changes that preceded it—you generally can't just make disastrous changes disappear. The one exception is when you've just committed a change, and it hasn't been pushed or pulled into another repository. That's when you can safely use the hg rollback command

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!

半世蒼涼 2024-07-29 07:49:39

“hg revert”不是这样做吗?

Doesn't "hg revert" do that?

不乱于心 2024-07-29 07:49:39

从阅读评论来看,您似乎想要一种简单地删除提交记录而不撤消对文件的更改的方法。 在 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 as filename.ext.orig, where ext is the original extension of the file. The reverted versions then take on the original filename. So what you could do is run hg 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.

尴尬癌患者 2024-07-29 07:49:39

还有来自“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文