开发中临时加塞了紧急任务应当如何处理

开发中临时加塞了紧急任务应当如何处理

十月 21, 2019

开发中临时加塞了紧急任务应当如何处理

  • git stash

将工作区修改的文件放入不影响下步工作的环境中

$ git status #假设工作区中修改了commit3文件
On branch temp
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: commit3

no changes added to commit (use "git add" and/or "git commit -a")
$ git stash #存入到不影响下步工作的环境当中
Saved working directory and index state WIP on temp: 645c351 Modified commit2
$ git stash list #查看stash列表,会有一个stash堆栈信息
stash@{0}: WIP on temp: 645c351 Modified commit2
$ git status #查看当前状态 当前工作区是一个干净的工作区 就可以继续下步工作
On branch temp
nothing to commit, working tree clean

紧急任务结束,重新恢复到接到紧急任务之前的状态

  • 不弹出stash
    • git stash apply
$ git stash apply #重新回到之前的状态,并且这个命令不谈出stash栈中的记录
On branch temp
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: commit3

no changes added to commit (use "git add" and/or "git commit -a")

$ git stash list #查看stash列表 之前的stash还存在 并且可以反复使用
stash@{0}: WIP on temp: 645c351 Modified commit2
  • 弹出stash
    • git stash pop
$ git stash pop #弹出stash 发现最后一行显示丢掉stash@{0}的记录
On branch temp
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: commit3

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (12397d0ad85cd29f39b1551753533aada85d3d42)
$ git stash list #再次查看stash列表 已经没有stash记录了