github之Pull Request

Pull Request简称PR,意思是自己修改源代码后,请求对方仓库采纳的一种行为。

找一个仓库,fork到自己名下

实例仓库为:https://github.com/ituring/first-pr

点击fork按钮,拉到自己的账号上来,,然后进行下面的操作,步骤如下:
1. git clone下载到本地
2. 本地创建特性分支
3. 在特性分支进行修改
4. 本地提交修改
5. git push向远端提交修改
6. 登陆github上进行PR

代码演示:

$ pwd
/c/Users/Administrator
Administrator@YOUNG-PC MINGW64 ~
#用这个命令克隆岛本地
$ git clone  git@github.com:x695/first-pr.git
Cloning into 'first-pr'...
remote: Counting objects: 997, done.
remote: Compressing objects: 100% (19/19), done.
Receiving objects: 100% (997/997), 234.68 KiB | 26.00 KiB/s, done.
Resolving deltas: 100% (639/639), done.
Checking connectivity... done.
Administrator@YOUNG-PC MINGW64 ~
#进入到下载的分支
$ cd first-pr/
Administrator@YOUNG-PC MINGW64 ~/first-pr (gh-pages)
$ ls
images/  index.html  javascripts/  params.json  README.md  stylesheets/
Administrator@YOUNG-PC MINGW64 ~/first-pr (gh-pages)
#查看分支信息,当前处在哪个分支下
$ git branch -a
* gh-pages
  remotes/origin/HEAD -> origin/gh-pages
  remotes/origin/feature/move-jquery-from-cdn-to-local
  remotes/origin/gh-pages
Administrator@YOUNG-PC MINGW64 ~/first-pr (gh-pages)
$ #创建一个特性分支
Administrator@YOUNG-PC MINGW64 ~/first-pr (gh-pages)
$ git checkout -b work origin/gh-pages
Branch work set up to track remote branch gh-pages from origin.
Switched to a new branch 'work'
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ ls
images/  index.html  javascripts/  params.json  README.md  stylesheets/
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ pwd
/c/Users/Administrator/first-pr
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
#用外部编辑器编辑后查看页面
$ git diff
diff --git a/index.html b/index.html
index cf5148d..15e0f14 100644
--- a/index.html
+++ b/index.html
@@ -235,6 +235,7 @@ GitHub pull request test!Thanks!此书为GitHub的经典入门教材,受益匪
 <p class="impression">书写的太好了,第一次尝试Pull Request(@ladyhua)</p>
 <p class="impression">学习github,来练练手。(^0^)</p>
 <p class="impression">大家好, 我是来学习的(@chengchaos)O(∩_∩)O哈!</p>
+<p class="impression">hi,我是thinker yang (@x695),到此一游,推荐此书O(∩_∩)O哈!</p>
 <h3>勘误</h3>
 <p>pp159</p>
 <p>误<code>git clone git@github.com/用户名/hello-world.git</code>
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
#提交到本地仓库
$ git add index.html
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git commit -m "添加我的说明"
[work 6a82c46] 添加我的说明
 1 file changed, 1 insertion(+)
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git log
commit 6a82c469aa170060708df407fef1fdfda3e0ba4d
Author: Thinker young <x695@qq.com>
Date:   Sun Mar 13 12:21:37 2016 +0800
    添加我的说明
commit d3e7d92b7b3fa94737f4368270608acc3409b2ec
Merge: 2f59968 5020c39
Author: Bin Liu <liubin@users.noreply.github.com>
Date:   Sat Mar 12 23:23:35 2016 +0800
    Merge pull request #202 from renyuntao/work
    Add my impression
commit 2f59968df5fd034aaefb99a3e3820e0676071ef8
Merge: 1bb7aa8 2758c79
Author: Bin Liu <liubin@users.noreply.github.com>
Date:   Sat Mar 12 23:21:32 2016 +0800
    Merge pull request #197 from Andrewgcluo/work
    Add my impression
commit 1bb7aa8e267f9fae22658dd99dfc32734071ae65
Merge: cabce16 5416f4f
Author: Bin Liu <liubin@users.noreply.github.com>
Date:   Sat Mar 12 23:20:57 2016 +0800
    Merge pull request #195 from hardfist/work
    first pb
commit cabce162bd0b66af98b33ff1c6400d515b595cdf
Merge: f3bcfd1 9d2053e
Author: Bin Liu <liubin@users.noreply.github.com>
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
#将刚创建的word分支推送到远程仓库上
$ git push origin work
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 383 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:x695/first-pr.git
 * [new branch]      work -> work
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
#再次查看分支信息
$ git branch -a
  gh-pages
* work
  remotes/origin/HEAD -> origin/gh-pages
  remotes/origin/feature/move-jquery-from-cdn-to-local
  remotes/origin/gh-pages
  remotes/origin/work
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ ls
images/  index.html  javascripts/  params.json  README.md  stylesheets/
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ vi index.html
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
#再次用vi修改后查看分支信息
$ git diff
diff --git a/index.html b/index.html
index 15e0f14..0de02d8 100644
--- a/index.html
+++ b/index.html
@@ -235,7 +235,7 @@ GitHub pull request test!Thanks!此书为GitHub的经典入门教材,受益匪
 <p class="impression">书写的太好了,第一次尝试Pull Request(@ladyhua)</p>
 <p class="impression">学习github,来练练手。(^0^)</p>
 <p class="impression">大家好, 我是来学习的(@chengchaos)O(∩_∩)O哈!</p>
-<p class="impression">hi,我是thinker yang (@x695),到此一游,推荐此书O(∩_∩)O哈!</p>
+<p class="impression">hi,我是thinker yang (@x695),到此一游,推荐此书O(∩_∩)O哈!我是第194个fork这个分支的。</p>
 <h3>勘误</h3>
 <p>pp159</p>
 <p>误<code>git clone git@github.com/用户名/hello-world.git</code>
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git add index.html
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git commit -am "Change:add 194 fork!"
[work 524f871] Change:add 194 fork!
 1 file changed, 1 insertion(+), 1 deletion(-)
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git push origin work
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 338 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:x695/first-pr.git
   6a82c46..524f871  work -> work
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)
$ git branch -a
  gh-pages
* work
  remotes/origin/HEAD -> origin/gh-pages
  remotes/origin/feature/move-jquery-from-cdn-to-local
  remotes/origin/gh-pages
  remotes/origin/work
Administrator@YOUNG-PC MINGW64 ~/first-pr (work)

做完上面的工作后,到个人的github网站上,点击work分支,然后再点击绿色的“New pull request”按钮,回弹出一个diff页面,同时附加评论框,写上自己的注释提交就可
以了

流程优化

像刚才那样如果进行各修改是有点麻烦,一般是对团队成员赋予编辑仓库的权限,成员可以直接创建分支,然后直接向master发送PR。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贤时间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值