git 分支合并、分支冲突

分支合并

分支合并的不同使用场景:

  • 合并指定分支到当前分支
  • 分支合并的冲突
  • (非)Fast-forward模式合并

一、合并指定分支到当前分支

合并指定分支到当前分支

git merge <branch name>

二、分支合并的冲突

当多分枝协作时,往往会产生一些冲突;

你的本地有两个分支master/dev,指向同一个版本,起始时状态相同,且只有一个readme.txt文件。

你在master上添加一段hello master,且add/git commit

然后切换到dev上添加了一段hello dev,且add/commit

此时,如果你想要合并devmaster上,就会发生分支合并的冲突

1. 解决分支合并冲突

当执行git merge <branch name>进行分支合并时,如果产生以下冲突,需要手动合并之后再提交;

$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

# when resolve the conflict, can exec the following commands:
# git add <files>
# git commit -m "descibe content"

# this command can show the commit graph.
# git log --graph

三、(非)Fast-forward模式合并

1. ff mode

当创建一个新的分支命名为dev,然后添加一个readme.txt文件到这个分支,切换到master做合并操作,执行:

# To execute merege command on master branch.

git merge dev

如果此时删除了dev分支, 那么分支的信息就消失了;这种合并模式称为Fast-Forward模式

2. --no-ff mode

如果使用--no-ff模式,表示禁用ff模式,执行:

# To execute merge command using --no-ff mode on master branch.

git merge --no-ff -m "describe message about this commit" dev

猜你喜欢

转载自blog.csdn.net/qq_39378657/article/details/113107852