$ git log --pretty=oneline 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment' a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment' 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function 4682c3261057305bdd616e23b64b0857d832627b added a todo file 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
$ git status #查看当前分支 改动情况 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: package.json
Untracked files: (use "git add <file>..." to include in what will be committed)
test.md
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash # 储藏变动的文件 到栈中 $ git stash list # 查看储藏的 代码 stash@{0}: WIP on master: 8aa5ad2 Git Demo $ git status # git stash 默认值储藏已经被跟踪的文件,如果文件没被跟踪并不会被储藏 On branch master Untracked files: (use "git add <file>..." to include in what will be committed)
test.md
nothing added to commit but untracked files present (use "git add" to track)
$ git stash pop # 取出最近被储藏的文件并删除该栈 $ git stash -u # 无论文件是否被跟踪只要有变化都将 储藏到栈中 $ git status On branch master nothing to commit, working tree clean
当有多个储藏的栈时,你可以通过git stash apply stash@{x}来指定取出储藏的文件。删除某个储藏的栈命令是git stash drop stash@{x}。
$ git log --pretty=format:"%h - %an, %ar : %s" ca82a6d - Scott Chacon, 6 years ago : changed the version number 085bb3b - Scott Chacon, 6 years ago : removed unnecessary test a11bef0 - Scott Chacon, 6 years ago : first commit
$ git add * $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README modified: CONTRIBUTING.md $ git reset HEAD CONTRIBUTING.md # 将文件从暂存区移除 Unstaged changes after reset: M CONTRIBUTING.md $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
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: CONTRIBUTING.md $ git checkout -- CONTRIBUTING.md # 撤销对文件的修改 $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)