git diff between two different files

GitDiff

Git Problem Overview


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 foo in HEAD, and bar in my current working tree.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

I believe using --no-index is what you're looking for:

git diff [<options>] --no-index [--] <path> <path>

as mentioned in the git manual:

> This form is to compare the given two paths on the filesystem. You can > omit the --no-index option when running the command in a working tree > controlled by Git and at least one of the paths points outside the > working tree, or when running the command outside a working tree > controlled by Git.

Solution 3 - Git

If you are using tortoise git you can right-click on a file and git a diff by: Right-clicking on the first file and through the tortoisegit submenu select "Diff later" Then on the second file you can also right-click on this, go to the tortoisegit submenu and then select "Diff with yourfilenamehere.txt"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMiJynView Question on Stackoverflow
Solution 1 - GitSteven WexlerView Answer on Stackoverflow
Solution 2 - Gitmh sattarianView Answer on Stackoverflow
Solution 3 - GitcamjocotemView Answer on Stackoverflow