Pull Request 的命令行管理

转自 http://www.ruanyifeng.com/blog/2017/07/pull_request.html

一、Pull Request 是什么?

二、Pull Request 的流程

三、git am

git am命令用于将一个 patch 文件,合并进入当前代码。

patch文件的获取:直接在commit的链接后加上.patch
例如:https://github.com/apache/activemq/commit/00921f2.patch

Github 对每个 PR 会自动生成一个 patch 文件。我们下载该文件,合并进本地代码,就可以在本地查看效果了。

$ curl -L http://github.com/cbeust/testng/pull/17.patch | git am

上面代码中,curl-L参数表示,如果有302跳转,curl会自动跟进。后面网址里面的/cbeust/testng是目标仓库,pull/17表示该仓库收到的第17个 PR。

如果 PR 只包含一个 commit,那么也可以直接下载这个 commit 的 patch 文件。

 $ curl https://github.com/sclasen/jcommander/commit/bd770141029f49bcfa2e0d6e6e6282b531e69179.patch | git am

上面代码中,网址里面的/sclasen/jcommander是代码变更所在的那个仓库。

四、创建远程仓库

另一种方法是为 PR 创建一个远程分支,追踪提交者的仓库。

    # 创建远程仓库,指向 PR 提交者的仓库
    $ git remote add nullin git://github.com/nullin/testng.git

    # 从该远程仓库拉取代码
    $ git fetch nullin

    # 将该仓库的某个分支合并到当前分支
    $ git merge kneath/error-page

    # 推送到自己的仓库
    $ git push origin master

五、cherry-pick

有时,PR 里面包含好几个 commit,但是你只想合并其中的一个或几个。

这时可以使用cherry-pick命令,挑出你感兴趣的 commit。

    # 建立远程分支,追踪提交者的仓库
    $ git remote add nullin git://github.com/nullin/testng.git

    # 从该远程仓库拉取代码
    $ git fetch nullin

    # 只将感兴趣的 commit 加入当前代码
    $ git cherry-pick commit1
    $ git cherry-pick commit2

    # 推送到自己的仓库
    $ git push origin master

猜你喜欢

转载自blog.csdn.net/csdnlijingran/article/details/82703515