대화 형 rebase 중에 두 개의 병합 커밋을 함께 스쿼시하는 간단한 솔루션을 원했습니다. 실제 사이의 범하지와git rebase interactive : squash merge together together
입니다X --- Y --------- M1 -------- M2 (my-feature)
/ / /
/ / /
a --- b --- c --- d --- e --- f (stable)
, 나는 두 번 최근에 합병 된 my-feature
지점을 가지고 :
내 저장소는 것 같습니다. 난 그냥 난 그냥 (아직 그 커밋을 게시하지 않은 경우) 마지막 두 병합 하나에 커밋 함께 스쿼시하려면, 그것은 자신의 출판 분기이기 때문에 my-feature
지점을 리베이스하고 싶지 않은
X --- Y ---- M (my-feature)
/ /
/ /
a --- ... -- f (stable)
나는 시도 :
git rebase -p -i M1^
하지만 내가 가지고 : 나는 마침내 무슨 짓을
Refusing to squash a merge: M2
은 다음과 같습니다
,536,git checkout my-feature
git reset --soft HEAD^ # remove the last commit (M2) but keep the changes in the index
git commit -m toto # redo the commit M2, this time it is not a merge commit
git rebase -p -i M1^ # do the rebase and squash the last commit
git diff M2 HEAD # test the commits are the same
이제 새로운 병합 커밋은 더 이상 병합 커밋으로 간주되지 않습니다 (첫 번째 부모 만 유지함). 따라서 :
git reset --soft HEAD^ # get ready to modify the commit
git stash # put away the index
git merge -s ours --no-commit stable # regenerate merge information (the second parent)
git stash apply # get the index back with the real merge in it
git commit -a # commit your merge
git diff M2 HEAD # test that you have the same commit again
커밋이 많으면 복잡해질 수 있습니다. 더 좋은 해결책이 있습니까? 감사합니다. .
밀드레드
음을 커밋 그들이 최선을 다하고 할 수있는 인덱스에 변경 사항을 적용합니다 두 번째 병합을 할 때 항상'--squash'를 사용하여 커밋을 생성하지 않고'git commit --amend'를 사용하여 이전 병합을 수정할 수 있습니다. – Mildred
이 작업을 수행 할 수 없으며 병합에서 병합 한 분기의 새 버전을 저장하지 않습니다. – Mildred