您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
27 开发中临时加塞了紧急任务...
发布时间:2020-07-19 15:58:33编辑:雪饮阅读()
比如说目前你正在开发一个客服系统
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ cat 1.txt
客服系统正在开发中。。。
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
然后突然线上出现一个bug要修复,那么我们需要将手头工作暂时暂停下,则需要用如下命令。
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash
warning: LF will be replaced by CRLF in 1.txt.
The file will have its original line endings in your working directory
Saved working directory and index state WIP on master: e1306dd 4.txt
然后可以看到stash列表中就会有了刚才我们暂停的任务
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash list
stash@{0}: WIP on master: e1306dd 4.txt
然后再查看工作区,我们工作区是干净的哈
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git status
On branch master
nothing to commit, working tree clean
恢复机制
当我们完成了bug修复,那么接下来我们需要将我们刚暂停的任务恢复过来,而恢复机制有apply恢复和pop恢复。
Apply恢复
通过apply我们发现已经成功恢复到之前暂停的任务了
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash apply
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git diff
diff --git a/1.txt b/1.txt
index e69de29..e98a173 100644
--- a/1.txt
+++ b/1.txt
@@ -0,0 +1 @@
+客服系统正在开发中。。。
此时我们发现stash列表中我们刚才暂停的任务仍会存在的
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash list
stash@{0}: WIP on master: e1306dd 4.txt
Pop恢复
既然用apply恢复后stash列表中仍旧存在刚才暂停的任务,那么
我们只需要重新恢复下工作区的状态到head即可
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git reset --hard head
HEAD is now at e1306dd 4.txt
然后我们接下来尝试pop恢复
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash pop
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (c028d9cf4de48e820be99b33ba83e5c102330fdb)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git diff
diff --git a/1.txt b/1.txt
index e69de29..e98a173 100644
--- a/1.txt
+++ b/1.txt
@@ -0,0 +1 @@
+客服系统正在开发中。。。
可见,pop也能实现将暂停任务恢复到工作区,那么接下来我们看看stash列表
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/we4 (master)
$ git stash list
此时会发现stash列表是空的,这就是pop恢复与apply恢复的区别。
关键字词:git,stash,pop,applay,head,hard,恢复,紧急任务
上一篇:26 正确删除文件的方法