简体   繁体   中英

Diffing two versions in Hg

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.?

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'

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM