Search code examples
gitdiffmeld

Is it possible to compare two directories in Git


I have installed Meld as diff tool in Git. Is it possible to compare two folders using Git or any other way? I tried the following command but nothing happened.

git diff /c/sample/folder1/ /c/sample/folder2/

Solution

  • If you want to compare two directories on your disk, no need for git :

    # use any suitable diff viewer : meld, kdiff3 ...
    meld /c/sample/folder1/ /c/sample/folder2/
    

    If you want to have a directory view for the diff between two commits in git :

    git difftool -d <commit1> <commit2>
    
    # you can also restrict this directory view to a subdir of your repo :
    git difftool -d <commit1> <commit2> -- lib/
    

    [update] to answer @DamianBirchler comment:

    to compare two directories within a commit:

    git difftool -d <commit>:path/to/dir1 <commit>:path/to/dir2
    

    This actually works with any two commits (anything that points to two trees within git actually):

    git difftool -d <commit1>:config  <commit2>:new/path/to/config