Created
November 24, 2010 23:55
-
-
Save czarneckid/714660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* We have 3 files that are modified in our local git repository, but we only want to stash 2 of those files. | |
* If we use git stash save, git will save all 3 files in the stash. How can we stash only README and TODO? | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
# Changed but not updated: | |
# (use "git add <file>..." to update what will be committed) | |
# (use "git checkout -- <file>..." to discard changes in working directory) | |
# | |
# modified: README | |
# modified: Rakefile | |
# modified: TODO | |
# | |
no changes added to commit (use "git add" and/or "git commit -a") | |
fossil:gitstash dczarnecki$ | |
* git stash save --patch to the rescue! From the git docs, "With --patch, you can interactively select hunks | |
from in the diff between HEAD and the working tree to be stashed." Let's do that. | |
fossil:gitstash dczarnecki$ git stash save --patch | |
diff --git a/README b/README | |
index e845566..b2c3719 100644 | |
--- a/README | |
+++ b/README | |
@@ -1 +1 @@ | |
-README | |
+README - Change | |
Stash this hunk [y,n,q,a,d,/,e,?]? y | |
diff --git a/Rakefile b/Rakefile | |
index a04c7c2..21e705d 100644 | |
--- a/Rakefile | |
+++ b/Rakefile | |
@@ -1 +1 @@ | |
-Rakefile | |
+Rakefile - Change | |
Stash this hunk [y,n,q,a,d,/,e,?]? n | |
diff --git a/TODO b/TODO | |
index 1333ed7..105cfa9 100644 | |
--- a/TODO | |
+++ b/TODO | |
@@ -1 +1 @@ | |
-TODO | |
+TODO - Change | |
Stash this hunk [y,n,q,a,d,/,e,?]? y | |
Saved working directory and index state WIP on master: 1dc1abb Added files. | |
* Look, look right there. README and TODO have been stashed away. | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
# Changed but not updated: | |
# (use "git add <file>..." to update what will be committed) | |
# (use "git checkout -- <file>..." to discard changes in working directory) | |
# | |
# modified: Rakefile | |
# | |
no changes added to commit (use "git add" and/or "git commit -a") | |
* Let's undo our changes to Rakefile | |
fossil:gitstash dczarnecki$ git checkout Rakefile | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
nothing to commit (working directory clean) | |
fossil:gitstash dczarnecki$ | |
* And now let's add a LICENSE file to the repository. You can imagine doing something more complex here like a git pull or rebase or something. | |
fossil:gitstash dczarnecki$ vi LICENSE | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
# Untracked files: | |
# (use "git add <file>..." to include in what will be committed) | |
# | |
# LICENSE | |
nothing added to commit but untracked files present (use "git add" to track) | |
fossil:gitstash dczarnecki$ git add LICENSE | |
fossil:gitstash dczarnecki$ git commit -a -m "Added LICENSE file" | |
[master 453ee68] Added LICENSE file | |
1 files changed, 1 insertions(+), 0 deletions(-) | |
create mode 100644 LICENSE | |
fossil:gitstash dczarnecki$ | |
* OK, time to unstash our README and TODO files. | |
fossil:gitstash dczarnecki$ git stash pop | |
# On branch master | |
# Changed but not updated: | |
# (use "git add <file>..." to update what will be committed) | |
# (use "git checkout -- <file>..." to discard changes in working directory) | |
# | |
# modified: README | |
# modified: TODO | |
# | |
no changes added to commit (use "git add" and/or "git commit -a") | |
Dropped refs/stash@{0} (248bc51adedbb0513c680261deede567255cc26a) | |
* And we see our changes to README and TODO. | |
fossil:gitstash dczarnecki$ git diff | |
diff --git a/README b/README | |
index e845566..b2c3719 100644 | |
--- a/README | |
+++ b/README | |
@@ -1 +1 @@ | |
-README | |
+README - Change | |
diff --git a/TODO b/TODO | |
index 1333ed7..105cfa9 100644 | |
--- a/TODO | |
+++ b/TODO | |
@@ -1 +1 @@ | |
-TODO | |
+TODO - Change | |
fossil:gitstash dczarnecki$ | |
fossil:gitstash dczarnecki$ git commit -a -m "Changed README and TODO" | |
[master 751a8c3] Changed README and TODO | |
2 files changed, 2 insertions(+), 2 deletions(-) | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
nothing to commit (working directory clean) | |
fossil:gitstash dczarnecki$ | |
* And this is the time on Sprockets when we dance! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment