1. git临时存储现有变更 git stash
git stash 存储现有变更
git stash apply 读取最新存储的变更
git stash list 查看存储变更列表
$ 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 stash@{2} 读取特定的存储
git stash drop stash@{0} 删除特定的存储
更多参考:
https://git-scm.com/book/zh/v1/Git-%E5%B7%A5%E5%85%B7-%E5%82%A8%E8%97%8F%EF%BC%88Stashing%EF%BC%89
2.git清空所有变更
git reset --hard # removes staged and working directory changes
## !! be very careful with these !!
## you may end up deleting what you don't want to
## read comments and manual.
git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :/ # CAUTION: as above, but cleans untracked and ignored files through the entire repo (without :/, the operation affects only the current directory)
http://stackoverflow.com/questions/1090309/git-undo-all-working-dir-changes-including-new-files
3. git 恢复单个文件
git checkout HEAD -- my-file.txt