git stash命令的作用就是将目前还不想提交的但是已经修改的内容进行保存,后续可以在任何分支上进行恢复。
git stash命令的作用范围包括工作区和暂存区中的内容,也就是说git add但没有git commit的内容和没有git add的内容都会被保存,所有的内容会保存在内存中,每次保存的内容会以stash@{index}为头标题的方式显示。

最新的保存内容永远为stash@{0}

git stash的常用命令:

1、git stash :保存所有未提交的修改。

PS D:\workspace\web> git stash
Saved working directory and index state WIP on test: 38680ae Merge branch 'test' into test
PS D:\workspace\web> git stash list
stash@{0}: WIP on test: 38680ae Merge branch 'test' into test

2、git stash save [message] :保存所有未提交的修改,并添加注释信息。(推荐使用方式)

PS D:\workspace\web> git stash save "router and totalRowTable"

3、git stash list :查看内存中所有保存的stash。

PS D:\workspace\web> git stash list
stash@{0}: On feature-v1.2.2: router and totalRowTable  //最新一次的保存
stash@{1}: On feature-v1.2.2: totalAmountRow1

4、git stash apply:将stash@{0}应用到当前目录下,内存中stash不做任何修改。
5、git stash apply "stash@{1}" || git stash apply --index 1:将stash@{1}的内容应用到当前目录下,内存中stash不做任何修改。

PS D:\workspace\web> git stash apply "stash@{1}"
Auto-merging src/pages/Voucher/FinanceDetail/components/ListForm.jsx
On branch test
Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified:   config/router.config.jsnew file:   src/components/TotalRowTable/index.jsxmodified:   src/locales/zh-CN/menu.jsnew file:   src/pages/TaskMgr/BatchRecords/index.jsxnew file:   src/pages/TaskMgr/TaskManager/index.jsxnew file:   src/pages/Voucher/AccountApproval/index.jsxnew file:   src/pages/Voucher/AccountRecords/index.jsxmodified:   src/pages/Voucher/FinanceDetail/components/ListForm.jsxmodified:   src/pages/Voucher/FinanceDetail/components/ListTable.jsxmodified:   src/pages/Voucher/FinanceDetail/index.jsxnew file:   src/pages/Voucher/models/getFinanceList.jsPS D:\workspace\web>

6、git stash pop
将stash@{0}中的内容应用到当前分支对应的工作目录上,并且在内存中删除stash@{0}。
注:该命令将以栈的执行方式删除,(栈:先进后出,后进先出)。

PS D:\workspace\web> git stash list  //总共有2条stash
stash@{1}: On feature-v1.2.2: test1
stash@{2}: On feature-v1.2.2: test2
PS D:\workspace\web> git stash pop  //执行pop命令
On branch test
Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified:   config/router.config.jsnew file:   src/components/TotalRowTable/index.jsxmodified:   src/locales/zh-CN/menu.jsnew file:   src/pages/TaskMgr/BatchRecords/index.jsxnew file:   src/pages/TaskMgr/TaskManager/index.jsxnew file:   src/pages/Voucher/AccountApproval/index.jsxnew file:   src/pages/Voucher/AccountRecords/index.jsxmodified:   src/pages/Voucher/FinanceDetail/components/ListForm.jsxmodified:   src/pages/Voucher/FinanceDetail/components/ListTable.jsxmodified:   src/pages/Voucher/FinanceDetail/index.jsxnew file:   src/pages/Voucher/models/getFinanceList.jsChanges 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:   config/config.jsDropped refs/stash@{0} (cfdd1ea72d1428cbf0d97866d9abb26d9cb83c25)
PS D:\workspace\web> git stash list  //再次查询stash,只有1条stash
stash@{0}: On feature-v1.2.2: test2
PS D:\workspace\orafl-financing-web>

7、git stash pop "stash@{1}" || git stash pop --index 1:将内存中的stash@{1}应用到当前目录,并在内存中删除当前stash。
8、git stash show:查看stash@{0}和当前目录的差异。

PS D:\workspace\web> git stash showconfig/router.config.js                            |  66 ++++++src/components/TotalRowTable/index.jsx             |  61 ++++++src/locales/zh-CN/menu.js                          |   8 +src/pages/TaskMgr/BatchRecords/index.jsx           |   0src/pages/TaskMgr/TaskManager/index.jsx            |   0src/pages/Voucher/AccountApproval/index.jsx        |   0src/pages/Voucher/AccountRecords/index.jsx         |   0.../Voucher/FinanceDetail/components/ListForm.jsx  |  20 +-.../Voucher/FinanceDetail/components/ListTable.jsx | 225 +++++++++++++++++----src/pages/Voucher/FinanceDetail/index.jsx          |  13 +-src/pages/Voucher/models/getFinanceList.js         |  34 ++++11 files changed, 367 insertions(+), 60 deletions(-)
PS D:\workspace\web>

9、git stash show -p:查看最新保存的stash和当前目录的差异详情。

PS D:\workspace\web> git stash show -p
diff --git a/config/router.config.js b/config/router.config.js
index a47aa25..d9fe82d 100644
--- a/config/router.config.js
+++ b/config/router.config.js
@@ -128,8 +128,74 @@ export default [}],},
+          // 凭证明细调帐审批
+          {+            path: '/voucher/accountApproval',
+            name: 'accountApproval',
+            routes: [
+              {+                path: '/voucher/accountApproval',
+                redirect: '/voucher/accountApproval/list',
+              },
+              {+                path: '/voucher/accountApproval/list',
+                component: './Voucher/AccountApproval',
+              }
+            ],
+          },
:

10、git stash clear :清除内存中所有的stash
11、git stash drop :从内存中移除stash@{0}
12、git stash drop "stash@{1} | "git stash drop -q 1 :从内存中移除索引为1的stash
13、git stash branch test "stash@{1}" :新建test分支并切换到test分支,并将stash@{1}的内容应用到test分支。

git stash的详细命令用法:

usage: git stash list [<options>]or: git stash show [<options>] [<stash>]or: git stash drop [-q|--quiet] [<stash>]or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]or: git stash branch <branchname> [<stash>]or: git stash clearor: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet][-u|--include-untracked] [-a|--all] [-m|--message <message>][--] [<pathspec>...]]or: git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet][-u|--include-untracked] [-a|--all] [<message>]PS D:\workspace\web>

查看更详细的说明,可以在控制台输出命令:git stash --help

参考:git stash详解

git stash用法总结相关推荐

  1. git stash用法

    原理:git stash 这个命令将当前的工作状态保存到 git 栈,在需要的时候再恢复. 写在前面:从栈中用的时候千万别搞错了!!! 使用场景:多个需求同时开发的时候,需要不同的分支,在一个需求没开 ...

  2. git stash用法详解

    文章转载自:https://blog.csdn.net/stone_yw/article/details/80795669 应用场景: 当正在dev分支上开发某个项目,这时项目中出现一个bug,需要紧 ...

  3. 20 个最常用的 Git 命令用法说明及示例

    作者 | Sahiti Kappagantula 译者 | 弯月,责编 | 屠敏 出品 | CSDN(ID:CSDNnews) 在这篇文章中,我将介绍在使用 Git 时最常使用的 20 个命令. 以下 ...

  4. Git:git stash存储文件修改

    git stash 用法总结和注意点 https://www.cnblogs.com/zndxall/archive/2018/09/04/9586088.html 常用git stash命令: (1 ...

  5. git stash的用法

    最近在使用Git管理项目工程的时候,遇到了很多问题,也学习到了很多关于Git常见使用的技巧,下面就其中关于Git Stash的用法和大家分享下. 首先,简单介绍下Git Stash命令的用法,详细的用 ...

  6. git stash 的用法

    1.引言 我们有时会遇到这样的情况,正在dev分支开发新功能,做到一半时有人过来反馈一个bug,让马上解决,但是新功能做到了一半你又不想提交,这时就可以使用git stash命令先把当前进度(工作区和 ...

  7. git shanchu stash_git stash用法

    常用git stash命令: (1)git stash save "save message"  : 执行存储时,添加备注,方便查找,只有git stash 也要可以的,但查找时不 ...

  8. git stash命令的用法

    stash的字面意思:隐藏,储藏 当我们以多人协同工作的方式基于同一个github仓库进行开发时,免不了遇到多人同时在本机对同一文件进行编辑的情况出现. 看一个具体的场景,当我使用git pull时, ...

  9. Git stash 的用法,将暂存区的内容缓存并移除,解决切换分支前的内容缓存问题

    git stash 如果当前分支还有任务没有做完,也不想提交,但此时需要切换或者创建其它分支,就可以使用stash将当前分支的所有修改(包括暂存区)先储藏起来:然后就可以切换到其它分支 在其它分支工作 ...

最新文章

  1. Android启动界面优化技巧-Splash Screens的正确方式
  2. Ubuntu 17.04 Chrome 安装
  3. 【学习笔记】【C语言】返回指针的函数
  4. Asp.NetCore依赖注入和管道方式的异常处理及日志记录
  5. Spring Boot项目优雅的全局异常处理方式(全网最新)
  6. 洛谷 P1404 平均数
  7. android listview 刷新不正确,Android中设置ListView内容刷新问题
  8. let和const注意点
  9. 为什么python最后一个元素下标是负一_Python负下标
  10. hdu-2112 HDU Today(最短路)
  11. linux 多线程超时中断,c#中的线程超时
  12. 数据结构基本知识点(二)
  13. ARM购HPC软件专家Allinea叫板英特尔和IBM
  14. 华为服务器重装操作系统,华为服务器安装操作系统
  15. anaconda下载
  16. Go的研习笔记-day11(以Java的视角学习Go)
  17. 在vs中怎样一次性的添加一个文件夹到解决方案里
  18. Easyx-----c语言实现图形化打砖块
  19. 读《Jonathan von Neumann and EDVAC》
  20. ubuntu18.04 下海康工业相机hikrobot_camera的使用及问题的解决

热门文章

  1. 【Java面试系列】GateWay异步非阻塞模型
  2. 生物信息/微生物组期刊推荐:Microbiome
  3. Chrome 浏览器安装 deepL 插件
  4. 路由控制解决双点双向问题
  5. vivoz5电池测试软件,5小时续航测试,vivo Z5x还剩多少电量?实测结果令人惊艳!...
  6. html书签导入苹果,如何将Safari书签迁移到Win10 Web浏览器
  7. goldengate mysql_Goldengate异构 mysql——oracl
  8. 云游戏就是云未来,阿里元境 x Unity x 长江学者这样说
  9. 零基础CSS入门教程(6)–style标签与注释
  10. chrome84版本解决加载flash插件问题