한 분기에서 다른 분기로 커밋을 복사하는 방법은 무엇입니까?
내 마스터로부터 두 가지 지점이 있습니다.
- v2.1 : (버전 2) 몇 달 동안 작업 해 왔습니다.
- wss : 마스터에 하나의 특정 기능을 추가하기 위해 어제 만들었습니다 (프로덕션 중).
어제의 커밋을 wss에서 v2.1로 복사하는 방법이 있습니까?
병합을 통해이 모든 작업을 수행 할 수있는 워크 플로가 있어야합니다.
- x - x - x (v2) - x - x - x (v2.1)
\
x - x - x (wss)
그래서 당신이해야 할 일은 git checkout v2.1
및 git merge wss
. 어떤 이유로이 작업을 정말로 할 수없고 git rebase 를 사용 하여 wss 브랜치를 올바른 위치로 이동할 수없는 경우 , 어딘가에서 단일 커밋을 가져 와서 다른 곳에 적용하는 명령은 git cherry-pick 입니다. 적용하려는 브랜치를 확인하고 git cherry-pick <SHA of commit to cherry-pick>
.
rebase가 당신을 구할 수있는 몇 가지 방법 :
기록이 다음과 같은 경우 :
- x - x - x (v2) - x - x - x (v2.1)
\
x - x - x (v2-only) - x - x - x (wss)
git rebase --onto v2 v2-only wss
wss를 v2로 직접 이동 하는 데 사용할 수 있습니다 .
- x - x - x (v2) - x - x - x (v2.1)
|\
| x - x - x (v2-only)
\
x - x - x (wss)
그러면 병합 할 수 있습니다! 당신은 정말, 정말, 경우 정말 병합 할 수있는 점에 얻을 수 효과적으로 한 번에 여러 체리 픽을 수행하려면, 당신은 여전히 REBASE를 사용할 수 있습니다 :
# wss-starting-point is the SHA1/branch immediately before the first commit to rebase
git branch wss-to-rebase wss
git rebase --onto v2.1 wss-starting-point wss-to-rebase
git checkout v2.1
git merge wss-to-rebase
참고 :이 작업을 수행하기 위해 추가 작업이 필요한 이유는 저장소에 중복 커밋을 생성하기 때문입니다. 이것은 정말 좋은 일이 아닙니다. 쉬운 분기와 병합의 요점은 커밋을 한곳에 만들고 필요한 곳에 병합하여 모든 것을 할 수 있다는 것입니다. 중복 커밋은 두 가지 분기를 병합하지 않으려는 의도를 의미합니다 (나중에 원하는 경우 충돌이 발생 함).
사용하다
git cherry-pick <commit>
현재 지점 에 적용 <commit>
합니다 .
필자는 내가 선택한 커밋을 교차 확인하고 gitk
대신 커밋 항목을 마우스 오른쪽 버튼으로 클릭하여 체리를 선택합니다.
(모든 위험과 함께) 더 자동으로 진행하고 어제 wss에서 발생한 모든 커밋을 가정하면 git log
with를 사용하여 커밋 목록을 생성 할 수 있습니다 ( --pretty
Jefromi 제안)
git log --reverse --since=yesterday --pretty=%H
그래서 당신이 사용한다고 가정하면 모든 것이 함께 bash
for commit in $(git log --reverse --since=yesterday --pretty=%H);
do
git cherry-pick $commit
done
여기에서 뭔가 잘못되면 (많은 잠재력이 있음) 라이브 체크 아웃에서 작동하기 때문에 문제가 있으므로 수동 체리 픽을 수행하거나 Jefromi가 제안한 리베이스를 사용하십시오.
git cherry-pick
: 일부 기존 커밋으로 인한 변경 사항 적용
(X, Y, Z) 커밋 이있는 분기 A 가 있다고 가정합니다 . 이러한 커밋을 분기 B 에 추가해야합니다 . 우리는 cherry-pick
작업 을 사용할 것 입니다.
When we use cherry-pick
, we should add commits on branch B in the same chronological order that the commits appear in Branch A.
cherry-pick does support a range of commits, but if you have merge commits in that range, it gets really complicated
git checkout B
git cherry-pick SHA-COMMIT-X
git cherry-pick SHA-COMMIT-Y
git cherry-pick SHA-COMMIT-Z
Example of workflow :
We can use cherry-pick
with options
-e or --edit : With this option, git cherry-pick will let you edit the commit message prior to committing.
-n or --no-commit : Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.
Here an interesting article concerning cherry-pick
.
You could create a patch from the commits that you want to copy and apply the patch to the destination branch.
Or if You are little less on the evangelist's side You can do a little ugly way I'm using. In deploy_template there are commits I want to copy on my master as branch deploy
git branch deploy deploy_template
git checkout deploy
git rebase master
This will create new branch deploy (I use -f to overwrite existing deploy branch) on deploy_template, then rebase this new branch onto master, leaving deploy_template untouched.
For the simple case of just copying the last commit from branch wss to v2.1, you can simply grab the commit id (git log --oneline | head -n 1
) and do:
git checkout v2.1
git merge <commit>
참고URL : https://stackoverflow.com/questions/2474353/how-to-copy-commits-from-one-branch-to-another
'Nice programing' 카테고리의 다른 글
디렉토리의 모든 파일과 폴더를 삭제하는 방법은 무엇입니까? (0) | 2020.10.02 |
---|---|
원격을 특정 커밋으로 재설정 (0) | 2020.10.02 |
속성 값으로 객체 배열에서 JavaScript 객체 가져 오기 [duplicate] (0) | 2020.09.30 |
파이썬에서 파일 크기를 확인하는 방법은 무엇입니까? (0) | 2020.09.30 |
문자열의 마지막 문자를 어떻게 얻을 수 있습니까? (0) | 2020.09.30 |