Staying In Sync With A Remote Repository

이번장에서는 pull request 가 뭔지 그리고 어떻게 만드는지, 그리고 관련된것들을 배운다.

Create a pull request

pull request내가 fork해서 가져가서 변경한 소스를 오리지날 소스 관리자에게 원래 소스에 변경사항을 포함할 수 있도록 요청하는것(내가 만든 소스가 갠찮으니 좀 써보시게~ 하는것)

동영상링크

Stay in sync with source project

어떤 소스를 fork해온뒤 local로 가져와서 작업하다보면 오리지날 외부저장소의 소스와 버전싱크가 맞지 않는다. 오리지날 소스역시 계속 업데이트 되기 때문이다. 이때 오리지널 소스를 로컬로 fetch 하는 방법이 있다.

git remote add upstream https://github.com/udacity/course-collaboration-travel-plans.git
# upstream 이라는 shortname으로 remote를 추가한다.
git fetch upstream master #혹은
git pull upstream master

pull 이란 녀석은 fetch + merge인 것이다.

git merge upstream/master

영상링크

rebase

여러개의 commit 들을 동시에 정리해줄수 있다. (여러가지 효과를 줄수가 있다.)

commit log가 아래와 같이있는 상황이라 가정한다. rebase로 C,D,E를 합쳐줄수 있다. 이렇게 합치면 C로그에 E버전의 코드가 저장된다.

*master branch     
A-B-C-D-E

우선 rebase는 엄청난 일이 일어나므로 backup branch를 만들어 준다.

git branch backup

 backup
*master

C까지 합칠것이기 때문에 git rebase -i HEAD~3 명령어를 쳐준다. 그러면 아래와 같은 화면이 생긴다.

pick eead910 C
pick 839b008 D
pick 5483707 E

# Rebase 3c70319..5483707 onto 3c70319 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

명령어를 적용해준뒤 wq 명령어로 나간다.

r eead910 C
s 839b008 D
s 5483707 E

#아래두개는 C와 합칠것이기 때문에 s명령어를 , C는 rebase했음을 표시하기 위해 r명령어 적용

r명령어를 적용한 C 커밋에 대해 메시지를 수정할수 있도록 아래와 같은 창이 다시 뜬다. 메시지를 수정해 주자.

Rebased (C,D,E)

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Jul 11 16:46:25 2017 +0900
#
# interactive rebase in progress; onto 3c70319
# Last command done (1 command done):
#    r eead910 C
# Next commands to do (2 remaining commands):
#    s 839b008 D
#    s 5483707 E
...

총 3개의 커밋을 rebase하기 때문에 아래와 같이 나머지 메시지들도 보여주면서 마지막 수정 기회를 제공한다. E는 지우고 D는 남겨두기로 했다.

# This is a combination of 3 commits.
# This is the 1st commit message:
Rebased (C,D,E)

# This is the commit message #2:

D

# This is the commit message #3:

#E

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
...

아래와 같은 메시지가 뜨면 rebase에 성공한것이다.

Successfully rebased and updated refs/heads/master

마지막으로 git log 명령어로 잘 됐는지 확인한다.

commit 6f20a66e34551d39a558c5c8a2242f5c69cfb522
Author: project42da <[email protected]>
Date:   Tue Jul 11 16:46:25 2017 +0900

    Rebased (C,D,E)

    D

commit 3c70319bdef05bf58a639379b389f970f29a7242
Author: project42da <[email protected]>
Date:   Tue Jul 11 16:45:39 2017 +0900

    B

commit a558c5c8a22424f58a639a13j450f3l1030ebf98
Author: project42da <[email protected]>
Date:   Tue Jul 11 16:44:33 2017 +0900

    A

최종 branch, commit log

      Rebased (master)
     /
A - B - C - D - E (backup)

이렇게 커밋을 병합했을 경우 이 커밋들을 가지고 있는 외부저장소에 push를 하면 reject당한다. 이때는 강제로 push 명령하여 올릴수 있는데, 이렇게되면 외부저장소의 커밋목록들 역시 합쳐진상태로 변경된다.

git push -f origin master

이제 배운내용들을 가지고 오픈소스프로젝트에 참여해보자!

results matching ""

    No results matching ""