Git - git diff

git

git diff origin..master > my.patch # pipes a diff into my.patch

git diff --stat HEAD // see diffstat of uncommitted work

git diff HEAD // see what changes you are committing

git diff HEAD@{1} filename // diff the current version against the previous version
git diff HEAD^
git diff HEAD^ -- /foo/bar/baz.txt

How can we compare different revisions?

# diff between two branches
git diff origin..master            # pipes a diff into PAGER
git diff origin..master > my.patch # pipes a diff into my.patch

# get diffstat of uncommitted work
git diff --stat HEAD

# diff between a specific revision and HEAD
git diff rev path

Why do we need to use 'git diff' with the —cache option?

You are now ready to commit. You can see what is about to be committed using git diff with the —cached option:

git diff --cached

(Without —cached, git diff will show you any changes that you’ve made but not yet added to the index.) You can also get a brief summary of the situation with 'git status'.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License