git 新建分支修复bug学习笔记

个人的几个疑问:

为什么不直接切换分支修改bug,然后合并?
Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git add bug.txt

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git checkout dev
error: Your local changes to the following files would be overwritten by checkout:
        bug.txt
Please commit your changes or stash them before you switch branches.
Aborting

在没有进行commit的时候无法切换分支。

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git checkout -b dev1
Switched to a new branch 'dev1'
D       bbbbug.txt
M       bug.txt

但是新建并切换就可以,具体并不知什么原因。

为什么不直接通过新建一个分支在新的分支上修复bug然后合并?
1.新建/切换dev分支
2.新建文件
3.切换到master分支
4.两个分支内容一样
1.新建/切换dev分支
2.修改文件
3.切换到master分支
4.两个分支内容一样
1.新建切换到dev分支
2.修改文件
3.使用add和commit命令
4.切换到master分支
5.提示找不到文件了

借用别人的理解:工作区和暂存区是一个公开的工作台,任何分支都会用到,并能看到工作台上最新的内容,只要在工作区、暂存区的改动未能够提交到某一个版本库(分支)中,那么在任何一个分支下都可以看得到这个工作区、暂存区的最新实时改动。 使用git stash就可以将暂存区的修改藏匿起来,使整个工作台看起来都是干净的。所以要清理整个工作台,那么前提是必须先将工作区的内容都add到暂存区中去。之后在干净的工作台上可以做另外一件紧急事件与藏匿起来的内容是完全独立的

dung!dung!dung!BUG!

刚刚输错了命令git 奔溃了,出现了一个问题,导致不能切换分支并且当前分支也无法删除:

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (dev1)
$ git checkout master
fatal: Unable to create 'C:/Users/Super Girl/learngit/gitskills/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (dev1)
$ git branch -d dev1
error: Cannot delete branch 'dev1' checked out at 'C:/Users/Super Girl/learngit/gitskills'

解决办法:
删除.git文件目录下的index.lock文件,注意这里的.git文件是隐藏的

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (dev1)
$ cd .git

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills/.git (GIT_DIR!)
$ rm index.lock
所以我们还是需要使用git stash
Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git add bug.txt

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git status
On branch featurel
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   bug.txt


Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git stash
Saved working directory and index state WIP on featurel: 97ba581 delete

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git status
On branch featurel
nothing to commit, working tree clean

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (master)
$ git checkout -b issue-101
Switched to a new branch 'issue-101'

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (issue-101)
$ git add bug.txt

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (issue-101)
$ git commit -m "fix bug 101"
[issue-101 7fb8d7e] fix bug 101
 1 file changed, 2 insertions(+), 2 deletions(-)

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (issue-101)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (master)
$ git merge --no-ff -m "merge bug fix 101" issue-101
Merge made by the 'recursive' strategy.
 bug.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (master)
$ git checkout featurel
Switched to branch 'featurel'

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git status
On branch featurel
nothing to commit, working tree clean

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git stash list
stash@{0}: WIP on featurel: 97ba581 delete

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git stash pop
On branch featurel
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   bug.txt

Dropped refs/stash@{0} (0c4702219ab240d8686b21b6934bec908307e3eb)

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git branch -d issue-101
error: The branch 'issue-101' is not fully merged.
If you are sure you want to delete it, run 'git branch -D issue-101'.

Super Girl@DESKTOP-NOEE1D4 MINGW64 ~/learngit/gitskills (featurel)
$ git branch -D issue-101
Deleted branch issue-101 (was 7fb8d7e).
小结:

修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除。
当手头工作没有完成时,先把现场工作git stash一下,然后再去修复bug,修复后,再git stash pop,回到工作现场,如果有多个stash,可用git stash clear清除。

版权声明

作者:HAIL

  出处:http://my.csdn.net/qq_35832982?locationNum=0&fps=1

  您的支持是对博主深入思考总结的最大鼓励。

  本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,尊重作者的劳动成果。

  参考:廖雪峰的官方网站
Bug分支:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值