Search code examples
gitdiff

git diff between two different files


In HEAD (the latest commit), I have a file named foo. In my current working tree, I renamed it to bar, and also edited it.

I want to git diff between foo in HEAD, and bar in my current working tree.


Solution

  • Specify the paths explicitly:

    git diff HEAD:full/path/to/foo full/path/to/bar

    Check out the --find-renames option in the git-diff docs.

    Credit: twaggs.

    git diff <path> <path> will compare two working-tree files as long as at least one of them is not in a git repo or the command is run from outside of a git repo. If you want to ensure git knows you are only comparing files in the working-tree (that is, on files in your directory rather than files added or commited to git), use git diff --no-index <path> <path>