将Mercurial修订分为两个:(1)移动文件,(2)编辑移动文件

发布于 2025-02-08 07:40:04 字数 415 浏览 2 评论 0原文

我有一个提交,将文件移至其他文件夹中,然后对这些文件进行更改。

我想将此修订版分为两个:

  1. 只有文件
  2. 对那些移动的文件进行其余的修改。

如何使用Mercurial/Hg?

我知道我可以将当​​前文件移动到其他文件夹(例如文件夹 - backup_folder),然后从头开始启动进行实际移动,然后HG COMMIT IT,最后重命名Backup_folder->文件夹并在顶部提交新的修订版。但是,我宁愿有一个hg命令,该命令可以根据hg log -vpr rev 重命名为”行的“ 重命名为 >显示。

I have a commit where I moved the files into a different folder, and then made changes to those files.

I want to split this revision into two:

  1. Only the file moves
  2. the rest of modifications on those moved files.

How can I accomplish this with Mercurial/hg ?

I know I can move the current files to a different folder (e.g. folder -> backup_folder), then start from scratch and do the actual move and then hg commit it, and finally rename backup_folder -> folder and commit a new revision on top. But, I rather have an hg command that intelligibly splits it all based upon the "rename from/rename to" lines that hg log -vpr REV shows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

猛虎独行 2025-02-15 07:40:04

假设现有的委托尚未被推动。如果是这样,那么这将无法正常工作,因为您无法修改公开的历史记录。

假设您的历史如下:

A-B-*

其中b具有移动&修改,*是当前的工作目录。

Say B包含从A/B/C/File1d/e/e/f/file2复制的结果。

追溯将b分为两个部分:


方法1:“ pure” mercurial(命令行)

  1. hg up a

  2. HG还原-r B

    (此时,工作目录将包含文件移动&文件更改)

  3. 每个移动的文件移动文件更改)

    &修改文件:

    hg cat -utput = a/b/c/file1 -rev = b d/e/f/file2

    (现在每个移动的文件都有其原始内容,但在新位置。)

  4. hg commit ...(创建b'

  5. hg还原-r b

    (恢复文件内容。)

  6. hg commit ...(创建c))

    所以现在您的历史就像:

    A-B
     \
      B'-C-*
  1. hg strip b

    (或者,如果您还使用HisteDit。)

    离开:

    A-B'-C-*

在#5处,您可能可以rebase也应该产生相同的结果,还应处理原始提交b其他


方法2:windows上的tortoisehg(主要是GUI)

,我使用tortoisehg,并作为Visual diff工具。鉴于该设置,我认为这样做会更快地做同样的事情:

  1. 在thg中,右键单击a,选择“ update”

  2. 右键单击b,选择“还原所有文件”

  3. 打开每个移动& Visual Diff(^d)中的修改文件

    • 恢复DIFF工具中的所有更改,保存文件
  4. commit ...

  5. 右键单击b,选择“还原所有文件”

  6. commit ...

  7. 右键单击b,修改历史记录,

大概是使用其他DIFF工具的剥离,或者在Windows上不使用类似的工作。


为了解决有关使用日志的问题...如果您像这样查看日志:

hg log --git -vpr  revision#

它将包含类似的行:

copy from a/b/c/file1
copy to d/e/f/file2

我知道没有简单 /直接的方法来获取HG来读取这些行并使用它们来重新启用命令。尽管这将列举所有复制的文件,但只需使用任何其他方式查看commit b也可以做到这一点。因此,不幸的是,我认为使用日志不会让您很远。

This assumes the existing commits haven't yet been pushed anywhere else. If so, then this will not work properly because you can't modify history that is public.

Let's say your history looks like this:

A-B-*

where B has the move & modifications, and * is the current working directory.

Say B contains to results of copying from a/b/c/file1 to d/e/f/file2.

To retroactively split B into two parts:


Approach 1: "Pure" Mercurial (command line)

  1. hg up A

  2. hg revert -r B

    (At this point the working directory will contain both the file moves & file changes)

  3. For each moved & modified file:

    hg cat --output=a/b/c/file1 --rev=B d/e/f/file2

    (Now each of the moved files will have its original contents, but in the new location.)

  4. hg commit ... (creates B')

  5. hg revert -r B

    (which restores the file contents.)

  6. hg commit ... (creates C)

    So now your history looks like:

    A-B
     \
      B'-C-*
  1. hg strip B

    (or you could use hg prune if you also use histedit.)

    Leaving:

    A-B'-C-*

At #5 you could probably rebase as well, which should produce the same outcome and also disposes of the original commit B which other


Approach 2: TortoiseHG on Windows (mostly GUI)

I use TortoiseHG and also WinMerge as the visual diff tool. Given that setup, I think it would be quicker to do the same thing this way:

  1. In THG, right click on A, choose "Update"

  2. Right click on B, choose "Revert All Files"

  3. Open each moved & modified file in visual Diff (^D)

    • Revert all changes in the diff tool, save the file
  4. Commit ...

  5. Right click on B, choose "Revert All Files"

  6. Commit ...

  7. Right click on B, Modify History, Strip

Presumably THG with other diff tools, or not on Windows, would work similarly.


To address the question about using the log... if you look at the log like so:

hg log --git -vpr  revision#

it will contain lines like:

copy from a/b/c/file1
copy to d/e/f/file2

I know of no simple / direct way to get hg to read those lines and use them to reapply commands. And though this will enumerate all the copied files, just looking at commit B using any other means would do that also. So I don't think using the log gets you very far, unfortunately.

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