Git手动合并

当收到他人的Pull Request后,该如何手动合并。实际上在很多情况下,Pull Request所含提交有可能造成合并冲突,那样的话GitHub不再、也不能提供自动合并功能,就必须采用手工合并的方式。
  • 将Pull Request发出者的派生版本库添加为一个新的源。(该操作是在本地的git目录下)
    例如收到来自gotgithub用户的Pull Request,不妨以wangxinyu为名添加新的源。
  • 此时版本库中有两个源,一个克隆时自动建立的origin,另外一个就是新增加的gotgithub。
    $ git remote -v
  • 获取远程版本库gotgithub的分支和提交。

    $ git fetch wangxinyu
  • 现在除了本地分支master外,还有若干远程分支,如下:

    $ git branch -a
  • 将远程分支remotes/wangxinyu/master(可简写为wangxinyu/master)合并到当前分支中。

    $ git merge wangxinyu/master
    Updating 00c6c4b..7ecdfe7
    Fast-forward
     errata.mkd |    1 +
     1 files changed, 1 insertions(+), 0 deletions(-)
  • 查看提交说明,看到此次合并没有产生不必要的合并提交。

    $ git log --graph -2
    * commit 7ecdfe7451412cfb2e65bb47c12cf2162e21c841
    | Author: Wang Sheng <[email protected]>
    | Date:   Tue Aug 16 10:17:53 2011 +0800
    |
    |     Fixed #3: should be 项目, not 项.
    |
    * commit 00c6c4bfab9824bd967440902ce87440f9e87852
    | Author: Jiang Xin <[email protected]>
    | Date:   Wed Aug 3 11:50:31 2011 +0800
    |
    |     Change font color for stronger text from red to brown.
  • 将合并推送到GitHub版本库中。

    $ git push

猜你喜欢

转载自pigga.iteye.com/blog/2374919