$ git status
Changes to be committed:(use "git reset HEAD <file>..." to unstage)
modified: index.html
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: lib/simplegit.rb
$ git stash
Saved working directory and index state \
"WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file(To restore them type "git stash apply")
可以看到工作目录是干净的:
$ git status
#On branch master
nothing to commit, working directory clean
$ git stash list
stash@{0}: WIP on master:049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master:21d80a5 added number to log
$ git stash apply
On branch master
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: index.html
modified: lib/simplegit.rb
no changes added to commit(use "git add" and/or "git commit -a")
$ git stash apply --index
On branch master
Changes to be committed:(use "git reset HEAD <file>..." to unstage)
modified: index.html
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: lib/simplegit.rb
应用选项只会尝试应用贮藏的工作,在堆栈上还有它,可以运行 git stash drop 加上将要移除的贮藏的名字来移除它:
$ git stash list
stash@{0}: WIP on master:049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master:21d80a5 added number to log
$ git stash drop stash@{0}
Dropped stash@{0}(364e91f3f268f0900bc3ee613f9f733e82aaed43)
$ git status -s
M index.html
M lib/simplegit.rb
$ git stash --keep-index
Saved working directory and index state WIP on master:1b65b17 added the index file
HEAD is now at 1b65b17 added the index file
$ git status -s
M index.html
$ git status -s
M index.html
M lib/simplegit.rb
?? new-file.txt
$ git stash -u
Saved working directory and index state WIP on master:1b65b17 added the index file
HEAD is now at 1b65b17 added the index file
$ git status -s
$
$ git stash --patch
diff --git a/lib/simplegit.rb b/lib/simplegit.rb
index 66d332e..8bb5674 100644--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -16,6+16,10 @@ class SimpleGit
return `#{git_cmd}2>&1`.chomp
end
end
++ def show(treeish ='master')+command("git show #{treeish}")+ end
end
test
Stash this hunk [y,n,q,a,d,/,e,?]? y
Saved working directory and index state WIP on master:1b65b17 added the index file
$ git stash branch testchanges
M index.html
M lib/simplegit.rb
Switched to a new branch 'testchanges'
On branch testchanges
Changes to be committed:(use "git reset HEAD <file>..." to unstage)
modified: index.html
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: lib/simplegit.rb
Dropped refs/stash@{0}(29d385a81d163dfd45a452a2ce816487a6b8b014)
$ git clean -x -i
Would remove the following items:
build.TMP test.o
*** Commands ***1: clean 2: filter by pattern 3: select by numbers 4: ask each 5: quit
6: help
What now>