Chinaunix首页 | 论坛 | 博客
  • 博客访问: 383092
  • 博文数量: 104
  • 博客积分: 652
  • 博客等级: 上士
  • 技术积分: 1477
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-04 15:20
文章分类

全部博文(104)

文章存档

2019年(1)

2015年(8)

2014年(6)

2013年(59)

2012年(30)

分类: LINUX

2013-10-22 12:41:54

创建分支:
# git branch dev
切换分支:
# git checkout dev

创建并切换dev分支:
# git checkout -b dev

查看当前分支:
# git branch

合并某分支到当前分支:
# git merge name

删除分支:
# git branch -d dev

当Git无法自动合并分支时,就必须首先解决冲突。常用git status查看冲突和解决方法。解决冲突后,再提交,合并完成。

查看分支合并图:
# git log --graph --pretty=oneline --abbrev-commit

通常,合并分支时,如果可能,Git会用“Fast forward”模式,但这种模式下,删除分支后,会丢掉分支信息。如果要强制禁用“Fast forward”模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。

ff模式和no-ff模式的区别:
FF模式:
# git merge dev
Updating edffae9..3613462
Fast-forward
 yy | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 yy

# git log --graph --pretty=oneline --abbrev-commit
* 3613462 add yy
* edffae9 add a b c files

NO-FF模式:
# git merge --no-ff -m "no-ff merge" dev
Merge made by the 'recursive' strategy.
 yy | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 yy

# git log --graph --pretty=oneline --abbrev-commit
*   dda94eb no-ff merge
|\  
| * ebd9d31 add yy
|/  
* edffae9 add a b c files



合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并。


BUG分支:
正在add、rm的文件还没有commit时,要修改其他文件,这时要用git stash来保存当前修改的状态,保存过后工作区就是干净的,进而可以创建分支来修复。
# git stash
Saved working directory and index state WIP on dev2: 5c2117f add ii
HEAD is now at 5c2117f add ii

# git status
# On branch dev2
nothing to commit, working directory clean

# git stash list
stash@{0}: WIP on dev2: 5c2117f add ii

stash恢复有两个办法:
一是用git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除;
另一种方式是用git stash pop,恢复的同时把stash内容也删了:
# git stash apply stash@{0}
#
git stash drop stash@{0}

# git stash pop
# On branch dev2
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
# modified:   ii
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (4e1a818b4e0f6e91af76bdb8325ab5b92ddbe61f)

阅读(1956) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~