Programing

Git의 다른 지점에있는 지점 인 '병합'이 아닌 '덮어 쓰기'는 어떻게합니까?

lottogame 2020. 4. 18. 09:29
반응형

Git의 다른 지점에있는 지점 인 '병합'이 아닌 '덮어 쓰기'는 어떻게합니까?


나는 두 가지를 가지고 emailstaging. staging최신 버전이며 더 이상 email지점 의 이전 변경 사항이 필요 하지 않지만 삭제하고 싶지 않습니다.

난 그냥 모든 내용을 덤프하려는 그래서 staging으로 email그래서 그들은 동일에 두 점 커밋. 가능합니까?


'ours'병합 전략을 사용할 수 있습니다 :

$ git checkout staging
$ git merge -s ours email # Merge branches, but use our branch head

'email'과 'staging'두 가지를 동일하게하려면 'email'분기에 태그를 지정한 다음 'email'분기를 'staging'하나로 재설정하십시오.

$ git checkout email
$ git tag old-email-branch
$ git reset --hard staging

'이메일'브랜치에서 '스테이징'브랜치를 리베이스 할 수도 있습니다. 그러나 결과에는 두 가지의 수정 사항이 포함됩니다.


다른 대답은 나에게 올바른 단서를 주었지만 완전히 도움이되지 않았습니다.

나를 위해 일한 것은 다음과 같습니다.

$ git checkout email
$ git tag old-email-branch # This is optional
$ git reset --hard staging
$
$ # Using a custom commit message for the merge below
$ git merge -m 'Merge -s our where _ours_ is the branch staging' -s ours origin/email
$ git push origin email

우리의 전략과 합병하는 네 번째 단계가 없으면 푸시는 빨리 감기가 아닌 업데이트로 간주되며 GitHub에서 거부됩니다.


나는 몇 가지 답변을 보았으며 그것이 충돌없이 해결할 수있는 유일한 절차입니다.

branch_old의 branch_new에서 모든 변경 사항을 원하면 다음을 수행하십시오.

git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new

이 네 가지 명령을 적용하면 문제없이 branch_old를 푸시 할 수 있습니다


나와 같고 병합을 처리하지 않으려면 병합 대신 힘을 사용하지 않는 위의 단계를 수행하면 산만 한 로그 용지 흔적이 만들어집니다.

git checkout email
git reset --hard staging
git push origin email --force

참고 : 이것은 절대로 다시 이메일로 내용을보고 싶지 않은 경우에만 해당됩니다.


모든 내용이의 내용 old_branch으로 업데이트 되도록 두 개의 브랜치를 병합하고 싶었습니다.new_branch

나를 위해 이것은 매력처럼 일했습니다.

$ git checkout new_branch
$ git merge -m 'merge message' -s ours origin/old_branch
$ git checkout old_branch
$ git merge new_branch
$ git push origin old_branch

어때요?

git branch -D email
git checkout staging
git checkout -b email
git push origin email --force-with-lease

다른 답변은 불완전하게 보였습니다.
아래에서 전체를 시도했지만 정상적으로 작동했습니다.

참고 :
1. 아래에서 시도하기 전에 저장소를 안전한 곳에 보관하십시오.

세부 사항 :
1. 모든 개발은 dev 브랜치에서 발생합니다
. 2. qa 브랜치는 dev의 동일한 사본입니다.
3. 때때로, dev 코드는 qa 브랜치로 이동 / 덮어 쓰기해야합니다.

dev 분기에서 qa 분기를 덮어 써야합니다.

1 부 :
아래 명령으로 이전 qa가 최신 개발자로 업데이트되었습니다.

git checkout dev
git merge -s ours qa
git checkout qa
git merge dev
git push

마지막 푸시에 대한 자동 주석은 다음과 같습니다.

// Output:
//  *<MYNAME> Merge branch 'qa' into dev,*  

이 주석은 역순으로 보입니다. 위 순서도 역순으로 보입니다

2 부:

다음은 예상치 못한 새로운 로컬 커밋, dev, 불필요한 커밋
을 버리고 개발자를 건드리지 않는 것입니다.

git checkout dev

// Output:
//  Switched to branch 'dev'  
//  Your branch is ahead of 'origin/dev' by 15 commits.  
//  (use "git push" to publish your local commits)


git reset --hard origin/dev  

//  Now we threw away the unexpected commits

3 부 :
모든 것이 예상 한대로인지 확인하십시오.

git status  

// Output:
//  *On branch dev  
//  Your branch is up-to-date with 'origin/dev'.  
//  nothing to commit, working tree clean*  

그게 다야.
1. 오래된 qa는 이제 새로운 dev 분기 코드로 덮어 씁니다
. 2. 로컬이 깨끗합니다 (원격 / dev는 변경되지 않았습니다)


git checkout email
git merge -m "Making email same as staging disregarding any conflicts from email in the process" -s recursive -X theirs staging

가장 쉬운 방법 :

//the branch you want to overwrite
git checkout email 

//reset to the new branch
git reset --hard origin/staging

// push to remote
git push -f

이제 이메일 분기와 준비가 동일합니다.

참고 : https://stackoverflow.com/questions/4624357/how-do-i-overwrite-rather-than-merge-a-branch-on-another-branch-in-git

반응형