https://git-scm.com/docs/git-stash

在git svn的时候使用,提交记录的时候,有部分文件的修改不需要commit。

在向svn进行git svn dcommit的时候,必须保存本地目录是clean的。所以需要进行stash,然后在dcommit

dcommit之后,需要在git stash aply

之前一直都在使用git stash 以及git stash apply

但是一直没有深入的研究,今天发现git stash是是会覆盖掉之前的stash的[stash apply仅仅取出最近的一次stash]

git stash --help  查看帮助手册

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

The modifications stashed away by this command can be listed with git stash list, inspected with git stash show, and restored (potentially on top of a different commit) with git stash apply. Calling git stash without any arguments is equivalent to git stash save. A stash is by default listed as "WIP on branchname …", but you can give a more descriptive message on the command line when you create one.

The latest stash you created is stored in refs/stash; older stashes are found in the reflog of this reference and can be named using the usual reflog syntax (e.g. stash@{0} is the most recently created stash, stash@{1} is the one before it,stash@{2.hours.ago} is also possible).

git stash list

查看之前缓存的所有stash

$ git stash list
stash@{0}: WIP on temp: 36b0f5f 删除HSDataFrameManager类中多余的代码      //第二次的stash,覆盖了第一次【git stash apply的时候,只能出现这一次的,上一次的不会出现】
stash@{1}: WIP on temp: 36b0f5f 删除HSDataFrameManager类中多余的代码      //第一次的stash
stash@{2}: WIP on temp: c723e17 接收到消息的时候,打印出消息类型,如果消息内部有
stash@{3}: WIP on temp: 18fa2a3 连接通讯模块时,需要将主窗体的窗口句柄传递给通讯

temp是分支的名字

第0个和第1个虽然看起来完全一样,但实际上是不同的

git stash show

查看list中的某一次stash

$ git stash show stash@{0}
ZBMYun/SourceCode/ZITakerHS/ZITaker/SystemConfig.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

$ git stash show stash@{1}
ZBMYun/SourceCode/ZITakerHS/ZITaker/UI/Main.cs | 2 +-
ZBMYun/SourceCode/ZITakerHS/ZITaker/ZbmStorage_Component.ini | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

git stash show stash@{0} -u

添加-u参数可以输出某一次stash的所有文件差异对比

git stash apply

可以apply指定的stash,如果你不指定的话,默认apply最近一次的stash

If you want to apply one of the older stashes, you can specify it by naming it, like this: git stash apply stash@{2}.

If you don’t specify a stash, Git assumes the most recent stash and tries to apply it:

git stash drop

$ git stash list
stash@{0}: WIP on local: 63b9f1b DebugInfoManager类,在FormMain加载的时候需要主
stash@{1}: WIP on svn: 78ab728 设备第一次上线后,直接发送采集数据,在这种情况下

$ git stash drop stash@{0}
Dropped stash@{0} (1136bc142780259d8541c7e3a605ff2250cc9427)

pop [--index] [-q|--quiet] [<stash>]

Remove a single stashed state from the stash list and apply it on top of the current working tree state, i.e., do the inverse operation of git stash save. The working directory must match the index.

Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards.

If the --index option is used, then tries to reinstate not only the working tree’s changes, but also the index’s ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally).

When no <stash> is given, stash@{0} is assumed, otherwise <stash> must be a reference of the form stash@{<revision>}.

Options:

save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]

Save your local modifications to a new stash, and run git reset --hard to revert them.

The <message> part is optional and gives the description along with the stashed state.

For quickly making a snapshot, you can omit both "save" and <message>, but giving only <message> does not trigger this action to prevent a misspelled subcommand from making an unwanted stash.

If the --keep-index option is used, all changes already added to the index are left intact.

If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state.

If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.

git stash的使用的更多相关文章

  1. Git Stash紧急处理问题,需要切分支

    在开发过程中,大家都遇到过bug,并且有些bug是需要紧急修复的. 当开发人员遇到这样的问题时,首先想到的是我新切一个分支,把它修复了,再合并到master上. 当时问题来了,你当前正在开发的分支上面 ...

  2. git stash 用法

    git stash用于将当前工作区的修改暂存起来,就像堆栈一样,可以随时将某一次缓存的修改再重新应用到当前工作区. 一旦用好了这个命令,会极大提高工作效率.   直接举例说明: 1.准备工作,首先初始 ...

  3. git stash和git stash pop

    git stash 可用来暂存当前正在进行的工作, 比如想pull 最新代码, 又不想加新commit, 或者另外一种情况,为了fix 一个紧急的bug,  先stash, 使返回到自己上一个comm ...

  4. git stash -u 添加新文件

    git 提交 有新文件执行    git stash -u ------ 如果已经执行git stash,会发现有UNtracked这个单词 说明新文件没有添加进去,此时 执行  git stash ...

  5. 每天一命令 git stash

    git stash  命令是用于保存当前进度的命令.该命令会保存当前工作区的改动.保存的改动是已经跟踪的文件的改动,对于未跟踪的改动stash是不会保存的. git stash 命令常用于分支切换的 ...

  6. git stash提交PR的正确步骤&git squash技术

    1.git stash梳理 1.1git stash的克隆与同步 首先整理下git stash的逻辑是这样 在本地做出了新的修改,提交时显示当前的版本不是最新版本,这时就需要先pull一下自己代码仓库 ...

  7. git merge git pull时候遇到冲突解决办法git stash

    在使用git pull代码时,经常会碰到有冲突的情况,提示如下信息: error: Your local changes to 'c/environ.c' would be overwritten b ...

  8. git stash简介

    原文:http://gitbook.liuhui998.com/4_5.html 一.基本操作 当你正在做一项复杂的工作时, 发现了一个和当前工作不相关但是又很讨厌的bug. 你这时想先修复bug再做 ...

  9. Git stash 常见用法

    Git stash git stash这个命令可以将当前的工作状态保存到git栈,在需要的时候再恢复 1.1 git stash  保存当前的工作区与暂存区的状态,把当前的工作隐藏起来,等以后需要的时 ...

  10. git stash恢复

    今天下午在使用Git命令进行代码管理时,因为自己一时疏忽直接把自己一天的劳动成果给弄丢了,这还了得,吓死宝宝了.真的,相信有代码丢失的朋友肯定能体会我当时的心情,不能体会我心情的那就祝你们也丢次代码, ...

随机推荐

  1. ASP.NET问题处理---targetFramwork=‘4.0’错误

    问题原因分析:系统没有下载 .NET framwork 4.0 版本的框架或者有下载但没使用. 解决办法: 打开iis上发布的“应用程序池”,并右键我们所发布的网站: 选择“添加应用程序池”: 最后选 ...

  2. SQL Server调优系列基础篇 - 性能调优介绍

    前言 关于SQL Server调优系列是一个庞大的内容体系,非一言两语能够分析清楚,本篇先就在SQL 调优中所最常用的查询计划进行解析,力图做好基础的掌握,夯实基本功!而后再谈谈整体的语句调优. 通过 ...

  3. IOC主要接口

  4. swift-08-元组分解和数组

    //1.有时候需要把元组中的数据拆分出来使用比如: var stu = ("范冰冰",30,"女") // 1)将stu中的数据赋值给三个变量. var (na ...

  5. c语言指针字符串与字符数组字符串的区别

    #include <stdio.h> int main() { //字符串常量,存放于内存常量区. //常量区区的内存具有缓存机制, //当不同指针指向的常量值相同时, //其实这些指针指 ...

  6. java新手笔记6 示例for

    1.计算天数 /*给定一个年月日,计算是一年的第几天 (如输入:2 15 结果:第46天) */ public class Demo1 { public static void main(String ...

  7. 04_XML_03_XMLDTD约束与校验

    [什么是XML约束] 在XML技术里,可以编写一个文档来约束一个XML文档的书写规范,称之为XML约束. 常见的XML约束技术有:XML DTD和XML Schema DTD(Document Typ ...

  8. poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2156 Solved: 818 [Submit][Statu ...

  9. cocos2d-x v3.0的window平台搭建和编译成andriod程序

    首先添加这个地址到系统环境变量,path 然后打开CMD,输入如下语句 现在就可以创建一个新项目了 这样一个空的cocos2d-x v3.0的项目就创建好了 接下来编译andriod程序 先在系统环境 ...

  10. 操作系统之进程篇(4)--经典进程间通信(IPC)问题

    1. 哲学家进餐问题: 问题描述: 五个哲学家在一个圆桌上进餐,每人的面前放了一盘意大利面,两个盘子之间有一个叉子,但是由于盘子里面的面条十分光滑,需要两个叉子才能进行就餐行为.餐桌的布局如下图所示: ...