git stash 用法
git stash用于将当前工作区的修改暂存起来,就像堆栈一样,可以随时将某一次缓存的修改再重新应用到当前工作区。
yang@Ubuntu64:~/code/linux/git$ vim hello.c
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..bdc92a5
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func1(void) {printf("this is func1");}
+void main(void) {return func1();}
yang@Ubuntu64:~/code/linux/git$ git stash
Saved working directory and index state WIP on master: 452b08d rename hello as hello.c
HEAD is now at 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ git status
On branch master
nothing to commit, working directory clean
yang@Ubuntu64:~/code/linux/git$ vim hello.c
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..9c5bff3
--- a/hello.c
+++ b/hello.c
@@ -, + @@
+some bad chenges....
yang@Ubuntu64:~/code/linux/git$ git checkout .
yang@Ubuntu64:~/code/linux/git$ git stash pop
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: hello.c no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{} (208ca2e2c0c455da554986a6770a74ad0de5b1e0)
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..bdc92a5
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func1(void) {printf("this is func1");}
+void main(void) {return func1();}
注意,git stash pop 弹出成功后,暂存列表里面就没有了,如果当前工作区不干净,弹出时有冲突,则暂存列表会继续保留修改。
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..bdc92a5
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func1(void) {printf("this is func1");}
+void main(void) {return func1();}
yang@Ubuntu64:~/code/linux/git$ git stash
Saved working directory and index state WIP on master: 452b08d rename hello as hello.c
HEAD is now at 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ git status
On branch master
nothing to commit, working directory clean
yang@Ubuntu64:~/code/linux/git$ vim hello.c
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..7fd0a13
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func2(void) {printf("this is func2");}
+void main(void) {return func2();}
yang@Ubuntu64:~/code/linux/git$ git stash
Saved working directory and index state WIP on master: 452b08d rename hello as hello.c
HEAD is now at 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ git status
On branch master
nothing to commit, working directory clean
yang@Ubuntu64:~/code/linux/git$ git stash list
stash@{}: WIP on master: 452b08d rename hello as hello.c
stash@{}: WIP on master: 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ git show stash@{}
commit 72e6a391bcad186ab24676aa1db8d5831c99cec9
Merge: 452b08d 6c95c30
Author: NickYang <yang@Ubuntu64>
Date: Sat Mar :: + WIP on master: 452b08d rename hello as hello.c diff --cc hello.c
index e69de29,e69de29..7fd0a13
--- a/hello.c
+++ b/hello.c
@@@ -, -, +, @@@
++void func2(void) {printf("this is func2");}
++void main(void) {return func2();}
yang@Ubuntu64:~/code/linux/git$ git show stash@{}
commit 7fcca4b66640c51ca76e637df03264b7c41885be
Merge: 452b08d 1c37881
Author: NickYang <yang@Ubuntu64>
Date: Sat Mar :: + WIP on master: 452b08d rename hello as hello.c diff --cc hello.c
index e69de29,e69de29..bdc92a5
--- a/hello.c
+++ b/hello.c
@@@ -, -, +, @@@
++void func1(void) {printf("this is func1");}
++void main(void) {return func1();}
发现stash@{0}对应func2的修改, stash@{1}对应func1的修改,原来新入栈的修改,其代号为0,循环命名。
yang@Ubuntu64:~/code/linux/git$ git stash apply stash@{}
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: hello.c no changes added to commit (use "git add" and/or "git commit -a")
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..bdc92a5
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func1(void) {printf("this is func1");}
+void main(void) {return func1();}
可见git stash apply可以将列表中任何一次修改应用到当前工作区,我们再次git stash list一把:
yang@Ubuntu64:~/code/linux/git$ git stash list
stash@{}: WIP on master: 452b08d rename hello as hello.c
stash@{}: WIP on master: 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ vim hello.c
yang@Ubuntu64:~/code/linux/git$ git diff
diff --git a/hello.c b/hello.c
index e69de29..786c214
--- a/hello.c
+++ b/hello.c
@@ -, +, @@
+void func3(void) {printf("this is func3");}
+void main(void) {return func3();}
yang@Ubuntu64:~/code/linux/git$ git stash save "this is func3"
Saved working directory and index state On master: this is func3
HEAD is now at 452b08d rename hello as hello.c
yang@Ubuntu64:~/code/linux/git$ git stash list
stash@{}: On master: this is func3
stash@{}: WIP on master: 452b08d rename hello as hello.c
stash@{}: WIP on master: 452b08d rename hello as hello.c
我们在save后面指定一个字符串,作为提醒,这样在git stash list查看时就能知道每一个代号对应的修改了。
git stash 用法的更多相关文章
- 转:Git: git stash 用法小结
一.应用场景 综合下网上的介绍和资料, git stash (git储藏)可用于以下情形: 发现有一个类是多余的,想删掉它又担心以后需要查看它的代码,想保存它但又不想增加一个脏的提交.这时就可以考虑 ...
- git stash用法
使用场景: 当前修改的代码还不足以提交commit,但又必须切换到其他分支,要想完成这样的操作就可以使用git stash git stash意思就是备份当前的工作区的内容,从最近的一次提交中读取相关 ...
- git stash 用法总结和注意点
常用git stash命令: (1)git stash save "save message" : 执行存储时,添加备注,方便查找,只有git stash 也要可以的,但查找时不 ...
- git stash应用
今天在看一个bug,之前一个分支的版本是正常的,在新的分支上上加了很多日志没找到原因,希望回溯到之前的版本,确定下从哪个提交引入的问题,但是还不想把现在的修改提交,也不希望在Git上看到当前修改的版本 ...
- 用好Git stash,助你事半功倍
git stash: 用法:git stash list [<选项>] 或:git stash show [<选项>] [<stash>] 或:git stash ...
- git stash命令及提交指定文件
一.git stash命令 常用git stash命令: (1)git stash save "save message" : 执行存储时,添加备注,方便查找,只有git stas ...
- Git stash 常见用法
Git stash git stash这个命令可以将当前的工作状态保存到git栈,在需要的时候再恢复 1.1 git stash 保存当前的工作区与暂存区的状态,把当前的工作隐藏起来,等以后需要的时 ...
- git stash的用法
使用git stash git stash的使用场景是这样的: 当你正在你的分支下进行开发时,这时候你可能需要切换到你的另一个分支去,你可能要pull新的代码下来,但是你又不想添加无用的commit. ...
- git stash解决代码merge出错
最近在使用git提交代码时,遇到一个问题,就是我修改了几个文件的代码,然后又想把自己代码库里面的代码更新到最新版本,然后不出所料,代码冲突了!作为一个喜欢解决问题的程序员,怎么会被这样的问题所困住呢? ...
随机推荐
- 基于小脚丫的ADC081S101 电压采集595数码管显示
RTL结构图 采集模块运用SPI 通讯 MISO方式收集数据 module ad_collect(input sddata,input rst_n,output reg cs,output reg s ...
- 从零开始学Python第六周:面向对象基础(需修改)
标签(空格分隔): 面向对象 一,面向对象基础 (1)面向对象概述 面向过程:根据业务逻辑从上到下写代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类 ...
- HotCode的原理及使用
1. JRbel介绍 JRebel是一套JavaEE开发工具.Jrebel可快速实现热部署,节省了大量重启时间,提高了个人开发效率.网上可搜索到破解版.JRebel是一款JAVA虚拟机插件,它使得JA ...
- rest api参数与content-type
最近为项目组提供rest api 时遇到了关于接口参数的传递问题,主要是没有充分考虑到第三方调用者的使用方式,应该尽量的去兼容公司之前提供出去的接口调用方式,这样可以降低第三方调用者的学习成本,尽管之 ...
- SqlServer灾备方案(本地)
如果你曾经有那么一个不经意的心跳来自于数据库数据损坏:错误的新增.更新.删除 .那么下面的方案一定能抚平你的创伤! 对于一个数据库小白来说,数据库的任何闪失带来的打击可说都是致命的.最初,我们让一个叫 ...
- 操作数数据类型 ntext 对于 max 运算符无效
SoStyle.chi_description AS chi_description, SoStyle.description AS eng_description, SoStyle.chi_qual ...
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
<pre name="code" class="objc"><pre name="code" class="ob ...
- 【Swift】UITableViewCell 中 TTTAttributedLabel 超链接无法点击的问题
前言 还以为是自己代码写的有问题,用法和别的地方都一样,但是这个是在 UITableViewCell 中使用,另外在 tableHeaderView 中使用也没用这个问题 —— 使用 TTTAttri ...
- iOS之深拷贝与浅拷贝
在最开始,我们需要清楚一些关于内存分配方式的基础知识. 一般来说分为栈.堆.静态变量存储区.全局变量存储区.代码区. 前两个大家都懂的.通常将后三个合并称之为静态存储区,存储的是一些全局变量.静态变量 ...
- Mac上idea快捷键
名称 快捷键 代码提示 ctrl + space 自动修正 alt + enter 查看调用链call hierarchy ctrl + H 查找文件 双击shift 查找类 command + N ...