diff --git a/basic/index.html b/basic/index.html index 48483ac..cc3bc25 100644 --- a/basic/index.html +++ b/basic/index.html @@ -57,33 +57,33 @@ layout: reference

-$ git status -s
-?? README
-?? hello.rb
+$ git status -s
+?? README
+?? hello.rb
 
So right now we have two untracked files. We can now add them.
-$ git add README hello.rb
+$ git add README hello.rb
 
Now if we run git status again, we'll see that they've been added.
-$ git status -s
-A  README
-A  hello.rb
+$ git status -s
+A  README
+A  hello.rb
 

OK, so now if we edit one of these files and run git status again, we will see something odd.

-$ vim README
-$ git status -s
-AM README
-A  hello.rb
+$ vim README
+$ git status -s
+AM README
+A  hello.rb
 

The 'AM' status means that the file has been modified on disk since we @@ -184,6 +184,7 @@ A hello.rb MM README D hello.rb +

In a nutshell, you run git status to see if anything has been modified @@ -191,9 +192,183 @@ A hello.rb commit a new snapshot and what will be recorded in it.

+ + +
+

+ + docs   + book + + git diff + shows diff of what is staged and what is modified but unstaged +

+ +
+

There are two main uses of the git diff command. One use we + will describe here, the other we will describe later in the + "Inspection and Comparison" + section. The way we're going to use it here is to describe the + changes that are staged or modified on disk but unstaged.

+ +

+ git diff + show diff of unstaged changes +

+ +

Without any extra arguments, a simple git diff will display + in unified diff format (a patch) what code or content you've changed in your + project since the last commit that are not yet staged for the next commit + snapshot.

+
+$ vim hello.rb
+$ git status -s
+ M hello.rb
+$ git diff
+diff --git a/hello.rb b/hello.rb
+index d62ac43..8d15d50 100644
+--- a/hello.rb
++++ b/hello.rb
+@@ -1,7 +1,7 @@
+ class HelloWorld
+   
+   def self.hello
+-    puts "hello world"
++    puts "hola mundo"
+   end
+ 
+ end
+
+ +

So where git status will show you what files have changed + and/or been staged since your last commit, git diff will + show you what those changes actually are, line by line. It's generally + a good follow-up command to git status +

+ +

+ git diff --cached + show diff of staged changes +

+ +

The git diff --cached command will show you what contents + have been staged. That is, this will show you the changes that will + currently go into the next commit snapshot. So, if you were to stage + the change to hello.rb in the example above, + git diff by itself won't show you any output because it will + only show you what is not yet staged. +

+ +
+$ git status -s
+ M hello.rb
+$ git add hello.rb 
+$ git status -s
+M  hello.rb
+$ git diff
+$ 
+
+ +

If you want to see the staged changes, you can run + git diff --cached instead.

+ +
+$ git status -s
+M  hello.rb
+$ git diff
+$ 
+$ git diff --cached
+diff --git a/hello.rb b/hello.rb
+index d62ac43..8d15d50 100644
+--- a/hello.rb
++++ b/hello.rb
+@@ -1,7 +1,7 @@
+ class HelloWorld
+   
+   def self.hello
+-    puts "hello world"
++    puts "hola mundo"
+   end
+ 
+ end
+
+ +

+ git diff HEAD + show diff of all staged or unstaged changes +

+ +

If you want to see both staged and unstaged changes together, you + can run git diff HEAD - this basically means you want to + see the difference between your working directory and the last commit, + ignoring the staging area. If we make another change to our + hello.rb file then we'll have some changes staged and some + changes unstaged. Here are what all three diff commands + will show you:

+
+$ vim hello.rb 
+$ git diff
+diff --git a/hello.rb b/hello.rb
+index 4f40006..2ae9ba4 100644
+--- a/hello.rb
++++ b/hello.rb
+@@ -1,7 +1,7 @@
+ class HelloWorld
+   
++  # says hello
+   def self.hello
+     puts "hola mundo"
+   end
+ 
+ end
+$ git diff --cached
+diff --git a/hello.rb b/hello.rb
+index 2aabb6e..4f40006 100644
+--- a/hello.rb
++++ b/hello.rb
+@@ -1,7 +1,7 @@
+ class HelloWorld
+ 
+   def self.hello
+-    puts "hello world"
++    puts "hola mundo"
+   end
+ 
+ end
+$ git diff HEAD
+diff --git a/hello.rb b/hello.rb
+index 2aabb6e..2ae9ba4 100644
+--- a/hello.rb
++++ b/hello.rb
+@@ -1,7 +1,8 @@
+ class HelloWorld
+ 
++  # says hello
+   def self.hello
+-    puts "hello world"
++    puts "hola mundo"
+   end
+ 
+ end
+
+ +

+ You can also provide a file path at the end of any of these options + to limit the diff output to a specific file or subdirectory. +

+ + +

+ In a nutshell, + you run git diff to see details of the git status + command - how files have been modified or staged on a line by line + basis. +

+ +
diff --git a/css/layout.css b/css/layout.css index be864c1..0c16f80 100755 --- a/css/layout.css +++ b/css/layout.css @@ -40,6 +40,7 @@ p.nutshell { margin-top: 10px; padding: 8px; background: #ffe; + color: #555; } .box code.code { @@ -51,9 +52,22 @@ p.nutshell { margin: 10px; color: #555; } -code.code b { color: #111; } -.red { color: #833; } +pre b { color: #111; } +.red { color: #d33; } .green { color: #383; } +.umber { color: #8A3324; } +.lblue { color: #55a; } + +.box h4 { + font-family:monospace; + margin-top: 20px; +} +.box h4 small { + color: #888; + font-size: 0.8em; + margin-left: 10px; + font-weight: normal; +} .note { float: right;