TIL no.15 - Git(Basic) - 7

박준규·2019년 10월 6일
0

Git

목록 보기
7/7

Git(Basic) - 6에서 merge로 통합하는 과정을 살펴보았습니다.
이제 rebase를 이용해 통합하는 방법에 대해 알아보겠습니다.


일단 전 단계에서 통합해준 명령을 취소해주겠습니다.

$ git reset --hard HEAD~

그리고 issue3로 checkout하고 master에 rebase하겠습니다.

$ git checkout issue3
Switched to branch 'issue3'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: pull 설명을 추가
Using index info to reconstruct a base tree...
<stdin>:13: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Failed to merge in the changes.
Patch failed at 0001 pull 설명을 추가

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".

Git(Basic) - 6에서 확인했듯이 myfile.txt 파일 내용이 충돌하는 것을 볼 수 있습니다.

branch 명령어 연습용
add: 변경 사항을 만들어서 인덱스에 등록해보기
<<<<<<< HEAD
commit: 인덱스의 상태를 기록하기
=======
pull: 원격 저장소의 내용을 가져오기
>>>>>>> issue3

rebase의 경우 충돌 부분을 수정 후 commit하지 않고 --continue옵션을 지정해 실행해야 합니다.

$ git add myfile.txt
$ git rebase --continue
Applying: pull 설명을 추가

만약 rebase자체를 취소하고 싶다면 --abort옵션을 지정하면 됩니다.
여기까지의 상황을 그림으로 표현하면 다음과 같습니다.

rebase는 issue3의 위치만 옮겨줄뿐 아직 master는 아직 issue3의 변경내용을 적용받지 못했습니다.

이제 master로 전환해 issue3의 변경 사항을 병합하겠습니다.

$ git checkout master
Switched to branch 'master'
$ git merge issue3
Updating 8f7aa27..96a0ff0
Fast-forward
 myfile.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

여기까지 상황을 그림으로 표현하면 다음과 같습니다.

merge와 차이는 이력이 다르다는 것입니다.
Git(Basic) - 6에서 merge로 병합했을 때 결과 그림을 위의 그림과 비교해보면 차이를 한 눈에 알 수 있습니다.

merge를 이용한 경우

profile
devzunky@gmail.com

0개의 댓글