Linux git(13)----Bug分支

17 篇文章 0 订阅
用到的新命令
1.git stash:当前工作现场“储藏”起来,等以后恢复现场后继续工作
2.git stash list:查看stash内容
3.git stash apply 工作现场:恢复工作现场,但stash内容不会删除,需要使用git stash drop来删除
4.git stash drop 工作现场:删除stash内容
5.git stash pop:恢复工作现场的同时把stash内容也删

1.先查看状态,在dev分支上工作,修改readme.txt
[root@VM_0_11_centos learn_git]# git status 
# On branch master
nothing to commit, working directory clean
[root@VM_0_11_centos learn_git]# cat readme.txt 
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes.
Creating a new branch is quick and simple.
分支管理策略
write somgthings    <== 正在dev工作
[root@VM_0_11_centos learn_git]# 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
<==有工作到一半,还不能add 和commit,但是要修改之前的bug.所以得 先储藏当前的工作状态,一遍后续恢复继续工作.


2.stash功能,可以把当前工作现场“储藏”起来
[root@VM_0_11_centos learn_git]# git stash 
Saved working directory and index state WIP on dev: 34b89e8 add one line
HEAD is now at 34b89e8 add one line
<==用git status查看工作区,就是干净的(除非有没有被Git管理的文件),因此可以放心地创建分支来修复bug。
[root@VM_0_11_centos learn_git]# git status
# On branch dev
nothing to commit, working directory clean


3.首先确定要在哪个分支上修复bug,假定需要在master分支上修复,就从master创建临时分支issue-101:
[root@VM_0_11_centos learn_git]# git checkout master 
Switched to branch 'master'
[root@VM_0_11_centos learn_git]# git checkout -b issue-101
Switched to a new branch 'issue-101'

4.现在修复bug,假设之前在readme.txt中添加的中文"分支管理策略"得改成英文"Branch management strategy"
[root@VM_0_11_centos learn_git]# cat readme.txt 
..省略..
分支管理策略
<== 这时候分支dev的redme.txt的新数据还没有同步到主分支,所以这里是看不到
[root@VM_0_11_centos learn_git]# vim readme.txt 
..省略..
Branch management strategy.

5.add 和 commit在issue-101分支下的readme.txt
[root@VM_0_11_centos learn_git]# git add readme.txt
[root@VM_0_11_centos learn_git]# git commit -m "Convert Chinese into English"
[issue-101 fa45608] Convert Chinese into English
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@VM_0_11_centos learn_git]# 

6.切换到master分支,合并issue-101分支
[root@VM_0_11_centos learn_git]# git checkout master 
[root@VM_0_11_centos learn_git]# git merge --no-ff -m "merged bug fix 101" issue-101 
Merge made by the 'recursive' strategy.
 readme.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

7.回到dev分支继续工作
[root@VM_0_11_centos learn_git]# git checkout dev 
Switched to branch 'dev'
[root@VM_0_11_centos learn_git]# git status <==dev工作区是干净的
# On branch dev
nothing to commit, working directory clean
[root@VM_0_11_centos learn_git]# cat readme.txt     <==数据也是旧
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes.
Creating a new branch is quick and simple.
分支管理策略

8.git stash list查看工作现场
[root@VM_0_11_centos learn_git]# git stash list 
stash@{0}: WIP on dev: 34b89e8 add one line

9.恢复工作现场有两种方式
a.用git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除;
[root@VM_0_11_centos learn_git]# git stash apply stash@{0} 
# 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
<== stash还在
[root@VM_0_11_centos learn_git]# git stash list 
stash@{0}: WIP on dev: 34b89e8 add one line
<== git stash drop 后跟tab减自动显示stash@{0}   删除stash
[root@VM_0_11_centos learn_git]# git stash drop stash@{0} 
Dropped stash@{0} (48f67052998b347e4d0f53c4a548089579883ae2)
<==再次查看后就没内容了
[root@VM_0_11_centos learn_git]# git stash list


b.另一种方式是用git stash pop,恢复的同时把stash内容也删了:
[root@VM_0_11_centos learn_git]# 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (193d3a75a330f696fe5e11b2ee663e21aae71ac7)
[root@VM_0_11_centos learn_git]# cat readme.txt 
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes.
Creating a new branch is quick and simple.
分支管理策略
write somgthings    <== 之前工作数据又回来了
再用  git stash list查看,就看不到任何stash内容了
[root@VM_0_11_centos learn_git]# git stash list

<==删除分支issue-101
[root@VM_0_11_centos learn_git]# git branch -D issue-101 
Deleted branch issue-101 (was fa45608).





1.切换回到master分支,提示错误如下
[root@VM_0_11_centos learn_git]# git checkout master 
error: Your local changes to the following files would be overwritten by checkout:
        readme.txt
Please, commit your changes or stash them before you can switch branches.
Aborting

2.需现将这次的工作内容add 和 commit
[root@VM_0_11_centos learn_git]# git add readme.txt
[root@VM_0_11_centos learn_git]# git commit -m "new readme.txt"
[dev 356e98e] new readme.txt
 1 file changed, 1 insertion(+)

3.再次切换到master
[root@VM_0_11_centos learn_git]# git checkout master 
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

4.合并dev分支到makter,提示错误,原因是 之前的bug将"分支管理策略"改成了"Branch management strategy."和dev下的不一致
[root@VM_0_11_centos learn_git]# git merge --no-ff -m "merge dev\readme.txt" dev
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.


5.查看readme.txt
[root@VM_0_11_centos learn_git]# cat readme.txt 
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes.
Creating a new branch is quick and simple.
<<<<<<< HEAD
Branch management strategy.
=======
分支管理策略<== dev分支下的依旧是中文
write somgthings
>>>>>>> dev


解决方法:
可参照<解决冲突>篇,删除6、8、9、11行后
[root@VM_0_11_centos learn_git]# git commit -m "dev\readme.txt add something"
[master 923a806] dev\readme.txt add something
[root@VM_0_11_centos learn_git]# git status <==工作区干净
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
[root@VM_0_11_centos learn_git]# 



 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值