Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show differences between some or all files? GIT

Tags:

git

As in the subject: how to show differences betwen some or all files?

Sorry i've screwed up my question. I meant differences betwen branches for one or multiple or all files.

like image 651
matiit Avatar asked Apr 09 '11 19:04

matiit


People also ask

How do you tell the difference in files in git?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

What is git diff command?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.


2 Answers

Or perhaps a bit more helpful:

git diff <commit1> <commit2> -- path/to/file.cpp path/to/anotherfile.cpp path/to/subdir

You can also (in e.g. bash)

git diff {<commit1>,<commit2>}:path/to/file.cpp

This way you can even

git diff <commit1>:path/to/file.cpp <commit2>:path/to/anotherfile.cpp

which is quite insane powerful, IMHO.

Replace <commit1> and <commit2> by any name of tag, branch (local or remote) or direct sha1 hash of a commit (this is known as a commit-ish)

To get really funky, you can specify tree-ish or blob hashes if you want. Do something completely silly with this for a sample:

$ git ls-tree HEAD^ | grep blob | sort -R | head -2
100644 blob 27785581e788049ac805fab1d75744dd7379735d    .gitignore
100644 blob 2821a5271ffd8e6b11bb26b8571f57e88ab81f38    TESTING

$ git diff --stat 2821a5271ffd8e6b11bb26b8571f57e88ab81f38 aa96765714a3058068c4425d801fab4b64e26066
 ...f38 => aa96765714a3058068c4425d801fab4b64e26066 |  155 +++++++++++++++++---
 1 files changed, 135 insertions(+), 20 deletions(-)

Now you won't usually do this, unless you have several versions of the 'same' file in you repo (which is iffy, if you ask me).

like image 55
sehe Avatar answered Nov 08 '22 22:11

sehe


git diff

Will show you the pending modified changes of un committed files

Review the docs on this command for the many different ways you can use it to see the differences between files

like image 30
jondavidjohn Avatar answered Nov 08 '22 23:11

jondavidjohn