Mercurial:如何修改最后一次提交? [英] Mercurial: how to amend the last commit?

查看:195
本文介绍了Mercurial:如何修改最后一次提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mercurial中寻找git commit --amend的对应部分,即一种修改工作副本链接到的提交的方法.我只对最后一次提交感兴趣,而不对先前的任意提交感兴趣.

此修订程序的要求是:

  • ,如果可能,不需要任何扩展名.它必须不要求非默认扩展名,即,与正式的Mercurial安装无关的扩展名.

  • 如果要修改的提交是我当前分支的负责人,则不得创建新负责人.如果提交不是头部,则可能会创建一个新的头部.

  • 该过程应该是安全,这样,如果由于某种原因修改失败,我希望恢复与修改前相同的工作副本和存储库状态.换句话说,如果修改本身可能失败,那么应该有一个故障保护过程来恢复工作副本和存储库状态.我指的是故障",它属于修正程序的性质(例如冲突),而不是文件系统相关的问题(例如访问限制,无法锁定文件以进行写入等). )

更新(1):

  • 该过程必须是可自动化的,因此它可以由GUI客户端执行,而无需任何用户交互.

更新(2):

    不得触摸工作目录中的
  • 文件(某些修改后的文件上可能存在文件系统锁定).这尤其意味着,一种可行的方法可能根本不需要干净的工作目录.

解决方案

随着命令行参考:

--amend标志可用于通过新提交修改工作目录的父级,该提交除了包含当前由hg状态报告的更改(如果有的话)之外,还包含父级中的更改.旧的提交存储在.hg/strip-backup中的备份捆绑包中(请参阅hg帮助捆绑包和hg帮助取消捆绑有关如何还原它的信息).

除非指定,否则消息,用户和日期均来自经修订的提交.如果未在命令行上指定消息,则编辑器将打开并显示已修改提交的消息.

很棒的事情是该机制是安全的",因为它依赖于相对较新的阶段"功能来防止可能会更改历史记录的更新,而这些历史记录已在本地存储库之外提供.

I'm looking for a counter-part of git commit --amend in Mercurial, i.e. a way to modify the commit which my working copy is linked to. I'm only interested in the last commit, not an arbitrary earlier commit.

The requirements for this amend-procedure are:

  • if possible, it should not require any extensions. It must not require non-default extensions, i.e. extensions which do not come with an official Mercurial installation.

  • if the commit to amend is one head of my current branch, no new head should be created. If the commit is not head, a new head may be created.

  • the procedure should be safe in a way that if for whatever reasons the amending fails, I want to have the same working copy and repository state restored as before the amending. With other words, if the amending itself can fail, there should be a fail-safe procedure to restore the working copy and repository state. I'm referring to "failures" which lie in the nature of the amend-procedure (like e.g. conflicts), not to file-system-related problems (like access restrictions, not being able to lock a file for writing, ...)

Update (1):

  • the procedure must be automatable, so it can be performed by a GUI client without any user interaction required.

Update (2):

  • files in the working directory must not be touched (there may be file system locks on certain modified files). This especially means, that a possible approach may at no point require a clean working directory.

解决方案

With the release of Mercurial 2.2, you can use the --amend option with hg commit to update the last commit with the current working directory

From the command line reference:

The --amend flag can be used to amend the parent of the working directory with a new commit that contains the changes in the parent in addition to those currently reported by hg status, if there are any. The old commit is stored in a backup bundle in .hg/strip-backup (see hg help bundle and hg help unbundle on how to restore it).

Message, user and date are taken from the amended commit unless specified. When a message isn't specified on the command line, the editor will open with the message of the amended commit.

The great thing is that this mechanism is "safe", because it relies on the relatively new "Phases" feature to prevent updates that would change history that's already been made available outside of the local repository.

这篇关于Mercurial:如何修改最后一次提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆