Programming

git에서 merge --squash와 rebase의 차이점은 무엇입니까?

procodes 2020. 3. 6. 07:53
반응형

git에서 merge --squash와 rebase의 차이점은 무엇입니까?


나는 git을 처음 사용하고 스쿼시와 rebase의 차이점을 이해하려고합니다. 알다시피 리베이스를 할 때 스쿼시를 수행합니다.


모두 git merge --squashgit rebase --interactive"숙청"커밋 생성 할 수 있습니다.
그러나 그들은 다른 목적으로 사용됩니다.

병합 관계를 표시하지 않고 대상 브랜치에서 스쿼시 커밋을 생성합니다.
(참고 : 커밋을 즉시 생성하지는 않습니다 : 추가가 필요합니다 git commit -m "squash branch")
소스 분기를 완전히 버리고 ( SO question 에서 가져온 스키마)에서 유용합니다 .

 git checkout stable

      X                   stable
     /                   
a---b---c---d---e---f---g tmp

에:

git merge --squash tmp
git commit -m "squash tmp"

      X-------------------G stable
     /                   
a---b---c---d---e---f---g tmp

그런 다음 tmp분기 를 삭제 합니다.


참고 : git merge--commit옵션을 있지만 사용할 수 없습니다 --squash. 없었다 결코 사용할 수 --commit--squash함께.
Git 2.22.1 (2019 년 3 분기) 이후이 비 호환성이 명시 적으로 나타납니다.

Vishal Verma ( )의 commit 1d14d0c (2019 년 5 월 24 일)를 참조하십시오 . ( Junio ​​C Hamano의해 병합 - 커밋 33f2790 , 2019 년 7 월 25 일)reloadbrain
gitster

merge: 쓰레기 --commit--squash

이전에는 --squash공급시 ' option_commit'가 자동으로 삭제되었습니다. 이것은 --commit명시 적으로 스쿼시의 커밋 없음 동작을 무시하려고 시도한 사용자에게는 놀라운 일이 아닙니다 .

git/git builtin/merge.c#cmd_merge() 이제 다음이 포함됩니다 :

if (option_commit > 0)
    die(_("You cannot combine --squash with --commit."));

새로운 기반에서 커밋의 일부 또는 전부를 재생하여 스쿼시 (또는 더 최근에는 "수정",이 SO 질문 참조 )하여 다음으로 바로 이동합니다.

git checkout tmp
git rebase -i stable

      stable
      X-------------------G tmp
     /                     
a---b

모든 커밋을 스쿼시하기로 선택한 경우 tmp(와 반대로 merge --squash일부를 재생하고 다른 스쿼시를 선택할 수 있습니다).

차이점은 다음과 같습니다.

  • merge소스 분기 ( tmp여기)를 건드리지 않고 원하는 곳에 단일 커밋을 만듭니다.
  • rebase다음을 사용 하여 동일한 소스 분기 (여전히 tmp) 진행할 수 있습니다 .
    • 새로운 기지
    • 더 깨끗한 역사

커밋 병합 : 브랜치에서 모든 커밋을 유지하고 기본 브랜치에서 커밋으로 인터리브여기에 이미지 설명을 입력하십시오

스쿼시 병합 : 변경 사항은 유지하지만 기록에서 개별 커밋을 생략합니다. 여기에 이미지 설명을 입력하십시오

Rebase: This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master

여기에 이미지 설명을 입력하십시오

More on here


Merge squash merges a tree (a sequence of commits) into a single commit. That is, it squashes all changes made in n commits into a single commit.

Rebasing is re-basing, that is, choosing a new base (parent commit) for a tree. Maybe the mercurial term for this is more clear: they call it transplant because it's just that: picking a new ground (parent commit, root) for a tree.

When doing an interactive rebase, you're given the option to either squash, pick, edit or skip the commits you are going to rebase.

Hope that was clear!

참고 URL : https://stackoverflow.com/questions/2427238/in-git-what-is-the-difference-between-merge-squash-and-rebase

반응형