Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git 사용 방법
  6. Git에서 브랜치를 사용하는 방법
  7. 브랜치 리베이스
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

브랜치 리베이스

issue3 브랜치를 메인 브랜치에 통합하는 또 다른 접근 방식은 git rebase 명령입니다. 리베이스를 사용하면 이 가이드의 앞에서 설명한 것처럼 기록 트리를 정리할 수 있습니다.

이전 병합을 실행 취소하여 시작하겠습니다.

$ git reset --hard HEAD~

지금 우리의 기록은 이렇습니다.

History before rebase

다음으로 issue3 브랜치로 전환하고 메인 브랜치로 리베이스합니다.

$ git checkout issue3
Switched to branch 'issue3'
$ git rebase main
Auto-merging sample.txt
CONFLICT (content): Merge conflict in sample.txt
error: could not apply 470d684... My Commit
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 470d684... My Commit

리베이스 중에 충돌이 발생하면 이를 해결하여 작업을 재개해야 합니다.

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
<<<<<<< HEAD
commit: Save the status of an index
=======
pull: Obtain the content of a remote repository
>>>>>>> issue3

충돌이 해결되면 --continue 옵션을 사용하여 리베이스를 재개할 수 있습니다.

변경 사항을 적용하기 전에 Git은 기본 텍스트 편집기(대부분의 Unix 시스템에서 Vim 또는 Emacs)를 열어 rebase 메시지를 편집할 수 있는 기회를 제공합니다. 리베이스 작업을 종료하고 롤백하려면 --abort 옵션을 사용하면 됩니다.

$ git add myfile.txt
$ git rebase --continue
Applying: append description of the pull command

이제 기록은 다음과 같습니다.

Current history

issue3 브랜치가 main으로 리베이스되므로 이제 빠른 병합을 실행할 수 있습니다.

메인 브랜치로 전환하고 issue3main과 병합합니다.

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

myfile.txt 파일의 내용은 이제 이전 병합의 내용과 동일합니다. 이제 기록은 다음과 같이 표시됩니다.

Current history

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life