为什么merge的时候要用squash

通常我们在用git做代码管理的时候,会在master/develope/release的基础上创建的自己的工作local branch,假设称之为“MyWorkBranch_local”。

然后我们在工作过程的中修改的代码会不断的提交到自己的local branch(MyWorkBranch_local),这样在这个branch上就会产生许多的commit。

当我们最终完成自己的代码,需要把自己branch(MyWorkBranch_local)的代码merge到master上,但是local branch上的commit的信息有时候太多,

没有必要保留过多的历史信息,只需要简洁明确的信息,这时候我们可以在master基础上再创建一个remote的branch,假设称之为"MyWorkBranch_remote",然后把local branch(MyWorkBranch_local)的代码先merge到remote的branch(MyWorkBranch_remote),并去掉历史信息,完整操作步骤如下:

1. git checkout master

2. git checkout -b MyWorkBranch_local

3. modify the codes and commit it to MyWorkBranch_local

4. git checkout master

5. git checkout -b MyWorkBranch_remote

6. git push origin MyWorkBranch_remote

7. git merge MyWorkBranch_local --squash

8. solve the confilicts

9. commit and push

10. create PR in github and merge to master/develope/release

还可以参考这篇文章,写的也很详细。

 

posted @ 2016-04-30 21:07  全栈工程师的修炼之路  阅读(438)  评论(0编辑  收藏  举报