Product SiteDocumentation Site

3.3.7. Staged files

The staged status is where the snapshot of all files that are ready to be committed reside. All files in this status will be committed when the command is given.

3.3.7.1. Viewing changes

Before committing the snapshots on the staged status, it is a good idea to check the changes made to ensure that they are acceptable. This is where the command git diff comes in.
$ git diff
diff --git a/filename b/filename
index 3cb747f..da65585 100644
--- a/filename
+++ b/filename
@@ -36,6 +36,10 @@ def main
		@commit.parents[0].parents[0].parents[0]
	end

+	some code
+		some more code
+	a comment
+	another change
-	a mistake
Running the git diff command with no parameters, as above, compares the working directory to what is in the staged status, displaying changes made but not yet committed.
It is also possible to compare the changes between the staged status and what the last commit was by using the --cached option.
$ git diff --cached
diff --git a/filename b/filename
new file mode 100644
index 0000000..03902a1
-- /dev/null
+++ b/filename
@@ -0,0 +1,5 @@
+file
+ by name1, name2
+ http://path/to/file
+
+ added information to file

Alternate command

In versions 1.6.1 and later of Git it is also possible to use the --staged option instead of --cached.