git-rebase의 onto 옵션, 어떤 경우에 사용하는 것인가?
<aside> 😌 Mermaid 다이어그램이 보이지 않을 경우, https://driip.notion.site/git-rebase-onto-3e2061788e6c4519be3555b5afeab30b 링크에서 읽어 주시면 감사하겠습니다.
</aside>
git-rebase는 기본적으로 1개 또는 2개의 인자를 받는다. 전체 Signature는 **git rebase <upstream> [<branch>]
**이다.
gitGraph
commit id: "A"
commit id: "B"
branch topic
commit id: "C"
commit id: "D"
checkout main
commit id: "E"
commit id: "F"
commit id: "G"
Signature는 **git rebase <upstream>
**이다.
가령 main
branch에 topic
branch를 rebase하고 싶다면, 현재 branch가 topic
인 상황에서 git rebase main
를 입력하면 된다.
$ git branch --show-current
topic
$ git rebase main
Successfully rebased and updated refs/heads/topic.
gitGraph
commit id: "A"
commit id: "B"
commit id: "E"
commit id: "F"
commit id: "G"
branch topic
commit id: "C'"
commit id: "D'"
Signature는 **git rebase <upstream> <branch>
**이다.
현재 branch가 topic
이 아닌 상황에서 git rebase master topic
을 입력해도 위와 똑같은 결과를 얻을 수 있다.
$ git rebase master topic
Successfully rebased and updated refs/heads/topic.
gitGraph
commit id: "A"
commit id: "B"
commit id: "E"
commit id: "F"
commit id: "G"
branch topic
commit id: "C'"
commit id: "D'"
이는 결국 git switch <branch>
후 git rebase <upstream>
을 수행하는 것과 동치이다.
--onto <newbase>
옵션git-rebase에는 다양한 옵션을 제공할 수 있는데, 그 중 하나가 --onto
옵션이다. 이를 사용할 경우 Signature는 **git rebase --onto <newbase> <upstream> [<branch>]
**가 된다.