GitHubでプルリクエストしてみる
Forkしないほうのプルリクエストを試してみる。
【参考】 GitHub初心者はForkしない方のPull Requestから入門しよう - QNYP Blog http://blog.qnyp.com/2013/05/28/pull-request-for-github-beginners/
現状
現状、sample.txtのファイルが1つある状態。
$ cat sample.txt 111 222 333 $ git status # On branch master nothing to commit (working directory clean) $ git branch * master
ブランチをpushする
ブランチを作成し、ファイルを変更する。
$ git checkout -b test Switched to a new branch 'test' $ vi sample.txt 111 222 333 444 $ git commit -a -m '444を追加' [test 35a6bb4] 444を追加 1 files changed, 1 insertions(+), 0 deletions(-)
GitHubにブランチを作成する。
$ git push origin test Password: Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 305 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To https://yk5656@github.com/yk5656/sample.git * [new branch] test -> test
修正を追加する場合
プルリクエストした後に修正が入った場合、
$ vi sample.txt 111 222 333 444 555 $ git commit -a -m '555を追加' [test edc1fbc] 555を追加 1 files changed, 1 insertions(+), 0 deletions(-)
再度プッシュすると、
$ git push Password: Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 310 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To https://yk5656@github.com/yk5656/sample.git 35a6bb4..edc1fbc test -> test
CloseやCommentなど
Closeボタンをクリックすると、プルリクエストを閉じることができる。
再度ボタンをクリックすると再オープンする。
また、コメントを書くこともできる。
競合した場合
マスター側でファイルを修正して、
$ vi sample.txt 111 222 333 666 $ git commit -a -m '666を追加' [master b4ee25b] 666を追加 1 files changed, 1 insertions(+), 0 deletions(-)
pushする。
$ git push Password: Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To https://yk5656@github.com/yk5656/sample.git 3cf8084..b4ee25b master -> master
GitHubでプルリクエストを見ると、マージできなくなっている。
この場合は、
ブランチにマスターをマージして、
$ git checkout test Switched to branch 'test' $ git merge master Auto-merging sample.txt CONFLICT (content): Merge conflict in sample.txt Automatic merge failed; fix conflicts and then commit the result.
競合を解消し、
$ vi sample.txt 111 222 333 444 555 666 $ git commit -a -m '666の競合を修正' [test af48c91] 666の競合を修正
再度pushする。
$ git push Password: Counting objects: 7, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 355 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To https://yk5656@github.com/yk5656/sample.git edc1fbc..af48c91 test -> test
ログ
マスター側でpullして修正を取り込む。
$ git checkout master $ git pull Password: remote: Counting objects: 1, done. remote: Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. From https://github.com/yk5656/sample b4ee25b..8977650 master -> origin/master Updating b4ee25b..8977650 Fast-forward sample.txt | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
ログを見ると、下記のようになっている。
$ git log --graph * commit 8977650df430216f1ebd1d705368a36cccd4a0f3 |\ Merge: b4ee25b af48c91 | | Author: yk5656 <ys.k@me.com> | | Date: Sat Mar 8 18:01:30 2014 +0900 | | | | Merge pull request #2 from yk5656/test | | | | 444を追加 のプルリクエスト の反映 | | | * commit af48c917acb1595692a3de10bc69e440c1ae4464 | |\ Merge: edc1fbc b4ee25b | |/ Author: Your Name <you@example.com> |/| Date: Tue Mar 4 15:12:59 2014 +0900 | | | | 666の競合を修正 | | * | commit b4ee25b528388645fc04953288911a4c2da49883 | | Author: Your Name <you@example.com> | | Date: Tue Mar 4 15:05:09 2014 +0900 | | | | 666を追加 | | | * commit edc1fbc136b1ce75782d12177f1d9aff3fe04697 | | Author: Your Name <you@example.com> | | Date: Tue Mar 4 15:01:31 2014 +0900 | | | | 555を追加 | | | * commit 35a6bb4c4751a8ed8e2c0944179eebf8d8902d36 |/ Author: Your Name <you@example.com> | Date: Tue Mar 4 14:30:48 2014 +0900 | | 444を追加 |