아래 텍스트의 경우 : master
은 A
의 잘못된 병합 이후 축적 된 차이를 반영합니다. 잘못된 병합의 자식으로 커밋 된 올바른 병합 결과를 원하므로 올바른 결과를 다시 마스터로 병합하고 두 팁을 병합 할 때 잘못된 병합과 올바른 병합 간의 차이점을 확인하고 병합합니다.
다음과 같은 방법으로 이야기의 내용을 어느 정도 반영합니다.
당신이 지금 가지고있는 병합베이스, featureA tip은 원하지 않습니다. 그 이후로 변경 사항이 병합되어 이후로 변경 사항은 master
에 있습니다. 원래 병합에서 전체 작업을 수행했다면 얻은 병합 기록과 결과가 필요합니다. 참조 할 수 있도록 커밋 그래프의 압축 된 버전 : 당신이 지금
# redo the original merge to get the right parents and the right content
git checkout $APM^ # checkout the original merge parent
git merge $APM^2 # do the correct merge with its other parent
git checkout -b AM # give this work a name
:
# /-B.....-\ featureB
# ---A0---B0---APM---BM---? master [APM, featureA partial merge, is bad]
# \-A...../??????????/ featureA [can keep history, merge rest of A?]
1 단계는 당신이 첫 번째 장소에서 원하는 병합 결과를 얻을 수 있습니다
# /-B......\
# ---A0---B0---APM---BM---?
# \ \-/-AM
# \-A.../-/
AM
의 부모가 $APM
과 같지만 올바른 결과입니다. $APM
이 무엇을했는지는 AM
에도 있습니다. AM
은 올바른 결과를 얻으려면 $APM
으로 변경해야 할 사항을 구체화합니다. $APM
커밋에있는 모든 내용이 AM
에 병합되었습니다 (리터럴 효과 있음).
git merge -s ours $APM # $APM is correctly incorported in AM. Tell git.
그리고 그 올바른 역사를 만든다 : AM
가 $APM
변경 한 세트를 반영, 그리고 master
다른를 반영한다.
git checkout master
git merge AM
git branch -d AM
을 나는이 권리를 가지고있는 경우에, 당신은 완료 : 시간 병합합니다.
git clone -s . ../wip # safety play: sandbox the changes
# do the above, and when you're satisfied you've got `master` correct,
cd ../$mainrepo
git checkout master # okay, incorporate the results
git pull # .
rm -rf ../wip # (everything in wip is now also here)
테스트 : 경우에 따라, 스크래치의 repo에 이상을 알림 또는주의로 그래도 뭔가 잘못을 가지고 그냥 경우
:
# drop this as file `script` in an empty directory and
# say `sh script` to recreate the described situation:
set -x
git init --template=
for f in {1..5}; do seq -ffile$f%4.0fx 10 >f$f; done
git add .
git commit -m'Initial commit'
git checkout -b featureA
sed -si s/4x/4-featureA/ f2 f3
git commit -am4featureA-f2f3
git checkout master
sed -si s/1x/1-master/ f1 f2 f3
git commit -am1master-f1f2f3
git checkout -b featureB
sed -si s/8x/8-featureB/ f3 f4
git commit -am8featureB-f3f4
git checkout master
git merge --no-commit featureA
git checkout HEAD f3
git commit -m'Merge branch featureA - less the f3 changes'
git tag APM
git merge --no-edit featureB
# and test the given solution:
git checkout -b AM APM^
git merge --no-edit featureA
git merge --no-edit -s ours APM
git checkout master
git merge --no-edit AM
# say `rm -rf f* .git` to cleanup
두 병합을 버리고 다시 실행하는 방법에 대해 어떻게 생각하십니까? –