git 进阶 (五)stash暂存

本文介绍了如何在工作中利用 Git 的 stash 功能进行临时保存未完成的工作。当需要中断当前任务去修复 bug 或处理其他紧急事项时,可以使用 `git stash save` 命令来保存工作区的修改。`-u` 选项可包含已添加到暂存区的文件,但不会存储未跟踪的文件或被 `.gitignore` 忽略的文件。通过 `git stash list` 查看储藏信息,`git stash apply` 和 `git stash pop` 分别用于恢复工作区的修改,后者同时会删除对应的储藏。`git stash drop` 直接删除储藏而不恢复,而 `git stash show` 可以显示储藏的详细变更记录。
摘要由CSDN通过智能技术生成

当要经常中断,修复bug时,导致弄乱正在进行中的工作时,那么需要储藏stash。

 

  • git stash save

储存当前modify内容,若要储存add的内容,需要加-u。

注意并不是-a,-a会导致未跟踪的文件,.gitignore以及exclude文件中明确忽略的文件被存储。

toney@sw2:~/work/project/dragon/core/code/customer/cus_dlinkg2$ git status 
On branch AAA
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        123.c

nothing added to commit but untracked files present (use "git add" to track)
toney@sw2:~/work/project/dragon/core/code/customer/cus_dlinkg2$ git stash save -u 123
Saved working directory and index state On AAA: 123
HEAD is now at e10192d b
  • git stash list

查看储藏信息:

toney@sw2:~/work/project/dragon/core/code/customer/cus_dlinkg2$ git stash list 
stash@{0}: On AAA: 123
  • git stash apply

从储藏中取出内容&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值