git diff
You can use Git diff to compare the differences between any two versions of a project.
$ git diff master.. test
This command displays only the differences between the two branches. If you want to find the differences between the common parent branches of master, test, and test, you replace the first two ‘.’ with three ‘.’.
$ git diff master… test
What will be committed
Git diff is usually used to find differences between the current working directory and the last commit and the local index. (Easiest and fastest)
$ git diff
The above commands will show up in the current working directory, without staged modifications (added into indexes) that will not be committed the next time you commit.
If you want to see something to commit next time (staged, added to index), you can run:
$ git diff –cached
The command above shows the difference between your current index and your last submission; These are committed when you run the “git commit” command without the “-a” parameter.
$ git diff HEAD
This command will show you all the differences between your working directory and the last time you committed, and will be committed when you run the “git commit -a” command.
More options for comparison
If you want to see the difference between the current working directory and another branch, you can use the following command:
$ git diff test
This will show the difference between your current working directory and another branch called ‘test’. You can also use a path qualifier to compare only one file or directory
$ git diff HEAD — ./lib
This command will show the difference between the lib directory in your current working directory and the last commit (or, more accurately, in the current branch).
Instead of looking at the detailed differences of each file, you can count which files were changed and how many rows were changed, using the ‘–stat’ parameter.
1 $ git diff --stat 2 3 layout/book_index_template.html | 8 ++- 4 5 text/05_Installing_Git/0_Source.markdown | 14 ++++++ 6 7 text/05_Installing_Git/1_Linux.markdown | 17 +++++++ 8 9 text/05_Installing_Git/2_Mac_104.markdown | 11 +++++ 10 11 text/05_Installing_Git/3_Mac_105.markdown | 8 ++++ 12 13 text/05_Installing_Git/4_Windows.markdown | 7 +++ 14 15 ... /1_Getting_a_Git_Repo.markdown | 7 +++- 16 17 ... /0_ Comparing_Commits_Git_Diff.markdown | 45 +++++++++++++++++++- 18 19 ... /0_ Hosting_Git_gitweb_repoorcz_github.markdown | 4 +- 20 21 9 files changed, 115 insertions(+), 6 deletions(-)Copy the code