git stash简单介绍
如果你此时在开发一个功能,预计需要1-2天开发完,老大突然跟你说有一个紧急bug需要修复,你不想commit当前代码破坏当前工作,那么这时候该怎么办呢?
这里就推荐一个git很不错的功能,git stash功能,暂存你当前的代码,方便你当前去完成其他要紧工作
主要命令
//暂存当前工作
git stash
//查看暂存列表
git stash list
//恢复最近一次暂存
git stash pop
使用介绍
你这里已经修改了一部分代码,需要紧急去修复一个bug
//查看当前修改状态
git status
On branch master
Your branch is up-to-date with 'origin/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: visitMyBlog.py
no changes added to commit (use "git add" and/or "git commit -a")
feiqianyousadeMacBook-Pro:forgeVisitMyblog yousa$
//暂存当前工作
git stash
//切换到工作分支完成工作
git checkout xxx
或者
git branch xxx
待修改完成后,切回自己的分支,查看查看暂存状态
//查看已经暂存的代码
git stash list
stash@{0}: WIP on master: 65f7e54 change user_agent
//恢复最近一次暂存
git stash pop
//这样就恢复了之前暂存的工作状态
On branch master
Your branch is up-to-date with 'origin/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: visitMyBlog.py
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (9ab02b46d95341069d8c31f71035d014eb6f0483)
这时候使用git status你就会发现之前的修改又恢复了,又可以继续愉快的开发了!:D