Comparing changes with git diffgit 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.
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.
There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff. I found this one of the key differences to version control systems like SVN (along with staging and ignoring directories).
This will do the +/-
rather than <
and >
.
diff -u file1 file2
Since GNU diffutils 3.4 the flag --color
has been added. Combining both makes the following:
diff --color -u file1 file2
The flag --color
also takes an argument, valid options are never
, always
, or auto
. Useful when you want to be more explicit on what needs to be done.
You can also use git diff --no-index -- A B
(via manpage).
Install colordiff.
Update your ~/.colordiffrc (copying /etc/colordiffrc first, if necessary):
# be more git-like:
plain=off
newtext=darkgreen
oldtext=darkred
diffstuff=darkcyan
Use colordiff -u file1 file2
for two files or colordiff -ruN path1 path2
for recursively comparing paths.
It's not exactly the same, but it's very close.
This is what I suggest and it's pretty close
diff -u FILE1 FILE2 | colordiff | less -R
colordiff
: You'll have to install this
brew install colordiff
on my Mac.port install colordiff
on some Macs.sudo apt-get install colordiff
on Debian or Ubuntu-R
: this tells Less to show colors instead of the raw codes.I ultimately used -w
because I didn't want to see whitespace diffs.
diff -w -u FILE1 FILE2 | colordiff | less -R
Edit: As suggested by @Ciprian Tomoiaga in the comment, you can make this a function and put it in your ~/.bashrc
file too.
function gdiff () { diff -u $@ | colordiff | less -R; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With