当前位置: 首页 > 工具软件 > git-bug > 使用案例 >

git--Bug分支 讲解步骤

司空叶五
2023-12-01

最近学习的git,如何修改bug

此时有两个分支:master,dev

root@gao:~/learngit# git branch
* dev
  master


当前正在dev上进行分支工作,但没有提交

root@gao:~/learngit# git status .
On branch dev
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.md

可以把当前工作现场存储起来

root@gao:~/learngit# git stash
Saved working directory and index state WIP on dev: a70f8a2 fix confict
HEAD is now at a70f8a2 fix confict

首先确定要在哪个分支上修复bug,假定需要在master分支上修复,就从master创建临时分支:

切换到master分支

root@gao:~/learngit# git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 12 commits.
  (use "git push" to publish your local commits)

创建分支issue-101

root@gao:~/learngit# git checkout -b issue-101
Switched to a new branch 'issue-101'

此时在issue-101分支

root@gao:~/learngit# git branch
  dev
* issue-101
  master


现在修复bug,需要把“Git is free software ...”改为“Git is a free software ...”,然后提交:

root@gao:~/learngit# git add README.md

提交

root@gao:~/learngit# git commit -m "fix bug 101"
[issue-101 5688f23] fix bug 101
 1 file changed, 1 insertion(+)

修复完成后,切换到master分支,并完成合并,最后删除issue-101分支:

切换master分支

root@gao:~/learngit# git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 12 commits.
  (use "git push" to publish your local commits)

合并分支

root@gao:~/learngit# git merge --no-ff -m "merged bug fix 101" issue-101
Merge made by the 'recursive' strategy.
 README.md | 1 +
 1 file changed, 1 insertion(+)

删除分支dev
git branch -d issue-101


接着回到dev分支干活了

切换到dev分支

root@gao:~/learngit# git checkout dev
Switched to branch 'dev'

查看当前的工作现场

root@gao:~/learngit# git stash list
stash@{0}: WIP on dev: a70f8a2 fix confict
stash@{1}: WIP on master: 281a585 modify Readme.md

恢复的同时把stash内容也删了

root@gao:~/learngit# git stash pop
On branch dev
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.md


 类似资料: