区分 Hg 中的两个版本

发布于 2024-11-16 22:41:05 字数 587 浏览 7 评论 0原文

我正在尝试查看项目的两个版本之间的差异。我最初想到的方式是:

  1. 创建新存储库
  2. 将第一个版本提交到存储库
  3. 用第二个版本覆盖第一个版本,将
  4. 两个版本提交到存储库 hg diff

这不起作用,因为当第二个版本覆盖时第一个版本 Mercurial 假定每个文件都已更改。实际上,只有几个文件被更改,我想看看每个文件中具体更改了什么。

WinDiff 为我提供了已更改文件的列表,但仅此而已,所以我真的很想使用 Hg 来获取详细信息。

编辑:我正在使用 Eclipse。我具体要做的是创建一个新的 Java 项目,使用 Eclipse 的导入功能导入我想要的源文件,然后将该项目提交到我的存储库。然后,我再次使用 import 将版本 2 导入到同一个项目中,以便覆盖第一个版本中的文件。我留下的文件名称相同,但都是版本 2 文件。然后我将新文件提交到存储库。

我的 Mercurial 版本是 1.8.3。执行上述步骤只给我一个变更集。

另外,在创建 diff 时,有没有办法指定仅 diff Java 文件,而不是文本或属性等?

I am trying to view the differences between two versions of a project. The way I initially thought to do it:

  1. Create new repository
  2. Commit first version to repository
  3. Overwrite first version with second version, commit to repository
  4. hg diff the two versions

This did not work, because when the second version overwrote the first version Mercurial assumed every single file was changed. In reality only a few files are changed, and I want to see what specifically was changed in each file.

WinDiff gives me a list of the files that were changed but that is it, so I would really like to use Hg to get the specifics.

EDIT: I am using Eclipse. What I specifically am doing is creating a new Java project, using Eclipse's import feature to import the source files I want, and then commit that project to my repository. I then use import again to import version 2 into the same project so that the files from the first are overwritten. I am left with files that are named the same but that are version 2 files. I then commit the new files to the repository.

My Mercurial version is 1.8.3. Doing the steps above gives me just one changeset.

Also, when creating the diff is there a way to specify to only diff Java files, not text or properties, etc.?

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

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

发布评论

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

评论(3

百善笑为先 2024-11-23 22:41:05

你的程序是健全的,只要记住像 Lasse 在评论中指出的那样使用 hg addremove 即可。因此,完整的过程是:

  1. 创建新存储库
  2. 将第一个版本导入存储库
  3. 运行 hg addhg commit
  4. 删除除 .hg 之外的所有文件
  5. 导入第二个版本到存储库
  6. 运行 hg addremovehg commit
  7. hg diff 两个版本

hg addremove 步骤甚至会检测以下文件:两个版本之间已重命名。你还写:

另外,在创建 diff 时,有没有办法指定仅比较 java 文件,而不是文本或属性等?

是的,您可以使用 --include 标志来实现此目的:

$ hg diff -I '**.java'

Your procedure is sound, just remember to use hg addremove like Lasse pointed out in the comments. So the full procedure is:

  1. Create new repository
  2. Import first version to repository
  3. Run hg add and hg commit
  4. Delete all files except .hg
  5. Import second version to repository
  6. Run hg addremove and hg commit
  7. hg diff the two versions

The hg addremove step will even detect files that have been renamed between the two versions. You also write:

Also, when creating the diff is there a way to specify to only diff java files, not text or properties, etc.?

Yes, you can use the --include flag for this:

$ hg diff -I '**.java'
素罗衫 2024-11-23 22:41:05

我不明白为什么你不能在项目的原始存储库上直接使用 Mercurial。

要查看项目的 REV1 和 REV2 之间 Java 文件发生了哪些变化:

hg diff -r REV1 -r REV2 -I **.java

I don't get it why your can't directly use Mercurial on the original repository of your project.

To see what are the changes to Java files between REV1 and REV2 of your project:

hg diff -r REV1 -r REV2 -I **.java
酒绊 2024-11-23 22:41:05

要在 Eclipse 中比较文件的两个版本:

  1. 右键单击该文件并转到 Team >显示历史记录
  2. 历史记录视图应该打开并显示文件的所有提交版本
  3. 双击要与之比较的头部版本。

To diff two versions of a file in eclipse:

  1. Right click on the file and go to Team > Show History
  2. The History view should open and show you all the committed versions of the file
  3. Double click on the version you want to diff the head with.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文