5

I am comparing two folders using a diff tool. I have tried a few different diff tools, but right now I'm using WinMerge. There are many files which show as unique to the right or left side, for example:

On the right we have: /bar/some_organized_characters.txt

On the left we have: /foo/some_similar_organized_characters.txt

The text file may have slight variations, but it's mostly similar. I would expect a tool to exist in most merge/diff tools which could tell you that these files are likely the "same" (meaning they have the same base), but the file has been moved, renamed, and slightly modified.

What I'm specifically trying to do is a "vendor merge." We have some customized software, and we want to merge the changes from a recent official release with the changes we have made. Many files have moved in the latest official release, and finding every move/rename by hand is difficult.

Buttons840
  • 9,239
  • 15
  • 58
  • 85

2 Answers2

3

use a version control tool to check for changes. Simply commit the structure as an initial commit. Then overwrite the structure with the new version and commit that. The patch view will show you moved items. I've been able to do this with Git very easily. These tools are made to see how something has changed and will dig into the contents of the file. In fact, in git, you can set the threshold of what percentage of changes in a file constitutes a move and change, vs a delete and create.

user229044
  • 232,980
  • 40
  • 330
  • 338
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • I haven't used Git, does SVN do the same? Right now SVN is just showing the original file as being deleted and the new file as being new, this means I can't compare how the contents of the file changed, because SVN doesn't see it as a move/rename. – Buttons840 Nov 15 '11 at 19:17
  • SVN has issues as it is URL-based vs. snapshot-based. I would recommend quickly downloading and installing git to do this. No server is necessary as it works just fine locally only. The commands that you need to know are `git init`, `git add -A` (add all changes), `git commit -m "some message"` and `git status`. Run the init one to make the current dir and all subdirs a repository. add everything, commit. delete the working folder except for the .git folder. Put the new version there, run git add and then git status. It should show you what changed. – Adam Dymitruk Nov 15 '11 at 19:22
  • What about Mercurial or Bazaar (or any other VCS), do they have similar features to Git? – Buttons840 Nov 15 '11 at 19:30
  • They probably will, but git is the most widespread so you'll get the most support for it. If you are going to use one for further purposes, I would strongly recommend git over the others. It's the most powerful one. I can at least help you with git for sure. – Adam Dymitruk Nov 15 '11 at 19:33
  • `git diff` can compare directories without creating a repo using `--no-index` https://stackoverflow.com/a/7945988/3163618 – qwr Jul 12 '20 at 03:27
  • I need something similar but not git diff because I am comparing 2 folders with big binary files. – Marko Kotar Feb 12 '23 at 11:47
1

I don't think this is possible with diff (I couldn't find it in the manpage).

However git diff detects this by default and can create patches that are applied with git apply in a similar way to patch. You can use it on arbitrary directories, not just repos, with --no-index (see Diffing between two entire directories/projects in hg or git?).

qwr
  • 9,525
  • 5
  • 58
  • 102