Git stash

echo "1st" >> pushed.txt
git add pushed.txt
git commit -m "1x: pushed.txt" pushed.txt
git push origin master
echo "2nd" >> pushed.txt
git add pushed.txt
git commit -m "2nd: pushed.txt" pushed.txt
echo "3rd" >> pushed.txt
git add pushed.txt
echo "4th" >> pushed.txt

echo "1st" >> committed.txt
git add committed.txt
git commit -m "1x: committed.txt" committed.txt
echo "2nd" >> committed.txt
git add committed.txt
echo "3rd" >> committed.txt

echo "1st" >> staged.txt
git add staged.txt
echo "2nd" >> staged.txt

echo "1st" >> working-directory.txt

Result:

$ cat pushed.txt
1st
2nd
3rd
4th
$ cat committed.txt
1st
2nd
3rd
$ cat staged.txt
1st
2nd
$ cat working-directory.txt
1st
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
 (use "git push" to publish your local commits)
Changes to be committed:
 (use "git reset HEAD <file>..." to unstage)
modified: committed.txt
 modified: pushed.txt
 new file: staged.txt
Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)
modified: committed.txt
 modified: pushed.txt
 modified: staged.txt
Untracked files:
 (use "git add <file>..." to include in what will be committed)
working-directory.txt
$ git diff
diff --git a/committed.txt b/committed.txt
index c8cac97..87cfd71 100644
--- a/committed.txt
+++ b/committed.txt
@@ -1,2 +1,3 @@
 1st
 2nd
+3rd
diff --git a/pushed.txt b/pushed.txt
index 87cfd71..4d5110c 100644
--- a/pushed.txt
+++ b/pushed.txt
@@ -1,3 +1,4 @@
 1st
 2nd
 3rd
+4th
diff --git a/staged.txt b/staged.txt
index 2a5d015..c8cac97 100644
--- a/staged.txt
+++ b/staged.txt
@@ -1 +1,2 @@
 1st
+2nd
$ git diff --cached
diff --git a/committed.txt b/committed.txt
index 2a5d015..c8cac97 100644
--- a/committed.txt
+++ b/committed.txt
@@ -1 +1,2 @@
 1st
+2nd
diff --git a/pushed.txt b/pushed.txt
index c8cac97..87cfd71 100644
--- a/pushed.txt
+++ b/pushed.txt
@@ -1,2 +1,3 @@
 1st
 2nd
+3rd
diff --git a/staged.txt b/staged.txt
new file mode 100644
index 0000000..2a5d015
--- /dev/null
+++ b/staged.txt
@@ -0,0 +1 @@
+1st
$ git diff HEAD
diff --git a/committed.txt b/committed.txt
index 2a5d015..87cfd71 100644
--- a/committed.txt
+++ b/committed.txt
@@ -1 +1,3 @@
 1st
+2nd
+3rd
diff --git a/pushed.txt b/pushed.txt
index c8cac97..4d5110c 100644
--- a/pushed.txt
+++ b/pushed.txt
@@ -1,2 +1,4 @@
 1st
 2nd
+3rd
+4th
diff --git a/staged.txt b/staged.txt
new file mode 100644
index 0000000..c8cac97
--- /dev/null
+++ b/staged.txt
@@ -0,0 +1,2 @@
+1st
+2nd
$ git diff working-directory.txt
$ git diff --cached working-directory.txt
$ git diff HEAD working-directory.txt
$ git stash # (non-indexed working-directory.txt file is not affected; the stage.txt file that was not committed but only added to index will be moved to stash so you cannot see it; indexed and committed oushed.txt and committed.txt files will be overridden to their commit version)
Saved working directory and index state WIP on master: 70a5d6f 1x: committed.txt
HEAD is now at 70a5d6f 1x: committed.txt
$ ls
committed.txt pushed.txt working-directory.txt
$ cat pushed.txt
1st
2nd
$ cat committed.txt
1st
$ cat working-directory.txt
1st
$ git diff
$ git diff --cached
$ git diff HEAD
$ git stash list
stash@{0}: WIP on master: 70a5d6f 1x: committed.txt
$ git stash show
 committed.txt | 2 ++
 pushed.txt | 2 ++
 staged.txt | 2 ++
 3 files changed, 6 insertions(+)
$ git stash apply
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
 (use "git push" to publish your local commits)
Changes to be committed:
 (use "git reset HEAD <file>..." to unstage)
 new file: staged.txt
Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)
 modified: committed.txt
 modified: pushed.txt
Untracked files:
 (use "git add <file>..." to include in what will be committed)
 working-directory.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s