Kohei Nozaki's blog 

Showing diffs


Posted on Sunday Mar 09, 2014 at 09:06AM in Technology


Assume this:

kyle-no-MacBook:gitprac5 kyle$ ls -l
total 8
-rw-r--r--+ 1 kyle  staff  5  3  9 09:04 hoge.txt
kyle-no-MacBook:gitprac5 kyle$ cat hoge.txt
hoge
kyle-no-MacBook:gitprac5 kyle$ git status
# On branch master
nothing to commit, working directory clean
kyle-no-MacBook:gitprac5 kyle$ 

Show unstaged changes

kyle-no-MacBook:gitprac5 kyle$ echo hogehoge >> hoge.txt
kyle-no-MacBook:gitprac5 kyle$ git diff
diff --git a/hoge.txt b/hoge.txt
index 2262de0..1904c09 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1 +1,2 @@
 hoge
+hogehoge
kyle-no-MacBook:gitprac5 kyle$ 

Show staged changes

kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt
kyle-no-MacBook:gitprac5 kyle$ git diff --cached
diff --git a/hoge.txt b/hoge.txt
index 2262de0..1904c09 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1 +1,2 @@
 hoge
+hogehoge
kyle-no-MacBook:gitprac5 kyle$ 
  • There are no unstaged changes now so result of git diff is empty
kyle-no-MacBook:gitprac5 kyle$ git diff
kyle-no-MacBook:gitprac5 kyle$ 

Show both of unstaged and staged changes

Edit hoge.txt again

kyle-no-MacBook:gitprac5 kyle$ echo hogehogehoge >> hoge.txt

Show unstaged changes

kyle-no-MacBook:gitprac5 kyle$ git diff
diff --git a/hoge.txt b/hoge.txt
index 1904c09..9d1d67e 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1,2 +1,3 @@
 hoge
 hogehoge
+hogehogehoge

Show staged changes

kyle-no-MacBook:gitprac5 kyle$ git diff --cached
diff --git a/hoge.txt b/hoge.txt
index 2262de0..1904c09 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1 +1,2 @@
 hoge
+hogehoge
  • This means that an another copy is created when we execute git add.

Show diff between 2 branches

kyle-no-MacBook:hello kyle$ git diff b4 origin/b4
diff --git a/README.md b/README.md
index b8630fa..9c70835 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1 @@
 b4-local1
-CANCEL
kyle-no-MacBook:hello kyle$ 



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed