学习目的
- 遇到临时bug需要紧急修复,在git如何处理?
- git如何进行工作区进行储藏,等待bug修复后的工作区恢复?
临时储藏
修改后查看工作区状态
1
2
3
4
5
6
7
8
9
10
11
12$ git status
On branch master
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits)
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")临时存储git stash
1
2$ git stash
Saved working directory and index state WIP on master: 118be5d --no-ff模式合并查看工作区
1
2
3
4
5
6$ git status
On branch master
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean新建bug分支’issue-001’
1
2$ git checkout -b issue-001
Switched to a new branch 'issue-001'修改文件查看,添加’bug分支测试!’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21$ cat readme.txt
Git is a version control system.
Git is free software.
Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
测试修改文件后各区状态!
测试git diff,查看工作区和分支文件的修改情况!
再次测试git diff对比工作区和版本库最新版本的区别。
测试撤销修改!
Creating a new branch is quick and simple.
测试分支合并冲突!
分支管理测试!
测试fast forward合并模式!
测试--no-ff合并模式!
bug分支测试!bug分支提交
1
2
3
4
5$ git add readme.txt
$ git commit -m "bug分支测试提交"
[issue-001 991a531] bug分支测试提交
1 file changed, 3 insertions(+), 1 deletion(-)切换到master分支,合并issue-001分支,删除issue-001分支
1
2
3
4
5
6
7
8
9
10
11
12
13
14$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits)
$ git merge --no-ff -m "bug分支测试合并" issue-001
Merge made by the 'recursive' strategy.
readme.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
$ git branch -d issue-001
Deleted branch issue-001 (was 991a531).查看工作区,查看现场储藏区,恢复储藏文件,再查看工作区
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30查看工作区
$ git status
On branch master
Your branch is ahead of 'origin/master' by 12 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
查看现场储藏区
$ git stash list
stash@{0}: WIP on master: 118be5d --no-ff模式合并
恢复储藏文件
$ git stash pop
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
再查看工作区
$ git status
On branch master
Your branch is ahead of 'origin/master' by 12 commits.
(use "git push" to publish your local commits)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
总结
- 正在工作区工作,突然进行紧急bug修复,储藏现场git stash;
- 新建bug分支,进行修复bug,提交修复,切换到master,合并bug分支,删除bug分支。
- 恢复工作区git stash pop(简写命令)。查看储藏列表git stash list;恢复储藏git stash apply;删除储藏git stash drop。
其他
QQ交流群: 264303060