はじめに
git で cherry-pick コマンド打ったら、コンフリクトになって理由が?になりました。
忘れてるので、手を動かして思います。
develop -> staging -> main ブランチの物語
-
create new branch "develop"
> git switch -c develop
-
add new file from "develop"
> ni a.txt-
+a1
-
commit and push "develop" to origin
> git push -u origin develop
-
create new branch "staging" from "develop"
> git switch -c staging
-
push "staging" to origin
> git push -u origin staging
-
add new file from "develop"
> git switch develop> ni b.txt-
+b1
-
commit and push "develop" to origin
> git push -u origin develop
-
merge "develop" to "staging"
> git switch staging> git merge develop> git push -u origin staging
-
merge "staging" to "main"
> git switch main> git merge staging> git push -u origin main
-
create tag "main"
> git tag -a v1.0 -m "first release"> git push origin v1.0
-
update file from "develop"
> git switch develop- a.txt, b.txt
-
+ab1
-
commit and push "develop" to origin
-
update file from "develop"
> git switch develop- a.txt, b.txt
-
+ab2
-
commit and push "develop" to origin
-
merge "develop" ("ab1" commit only) to "staging"
-
> git logfrom develop - update ab1 : 05810ac4784a45d48429a4b9e6edd61d23f42a6a
- update ab2 : 10376018a0193a90b197ab5dac982ec48c53bc26
> git switch staging> git cherry-pick 05810ac4784a45d48429a4b9e6edd61d23f42a6a> git push -u origin staging
-
-
update file from "develop"
> git switch develop- a.txt, b.txt
-
+ab3
-
commit and push "develop" to origin
-
merge "develop" ("ab3" commit only) to "staging"
-
> git logfrom "develop"- update ab1 : 05810ac4784a45d48429a4b9e6edd61d23f42a6a
- update ab2 : 10376018a0193a90b197ab5dac982ec48c53bc26
- update ab3 : d754dd1c7bff0dc69bd12bd6f00662d43bcdf50b
> git switch staging-
> git reset --hard(reset all from local staging branch) -
> git cherry-pick d754dd1c7bff0dc69bd12bd6f00662d43bcdf50bab3 error: could not apply d754dd1... update ab3hint: After resolving the conflicts, mark them with...-
> git cherry-pick --abort(abort cherry-pick) - Q : why conflict
- A : ab3 in ab2
-
> git cherry-pick 10376018a0193a90b197ab5dac982ec48c53bc26ab2 -
> git push -u origin staging(success ab2)
-
-
create "feature" branch at update file from "develop"
> git switch develop> git switch -c feature/update-ab4- a.txt, b.txt
-
+ab4
-
commit and push "feature/update-ab4" to origin
-
merge "feature/update-ab4" to "develop"
> git switch develop> git merge feature/update-ab4> git push -u origin develop
-
merge "feature/update-ab4" ("ab4" commit only) to "staging"
> git switch feature/update-ab4-
> git logfrom "feature/update-ab4"- update ab4 : dc4ce3a3ad16b70e267b53ab1f496de34da8baa6
> git switch staging-
> git cherry-pick dc4ce3a3ad16b70e267b53ab1f496de34da8baa6Auto-merging a.txtCONFLICT (content): Merge conflict in a.txtAuto-merging b.txtCONFLICT (content): Merge conflict in b.txterror: could not apply dc4ce3a... update ab4hint: After resolving the conflicts, mark them with...-
> git cherry-pick --abort(abort cherry-pick)
-
create "feature" branch at update file from "develop"
> git switch develop> git switch -c feature/update-ab5
-
create "feature" branch at update file from "develop"
> git switch develop> git switch -c feature/update-ab6
-
add "ab5" to file from "feature/update-ab5"
> git switch feature/update-ab5- a.txt, b.txt
-
+ab5
-
commit and push "feature/update-ab5" to origin
-
add "ab6" to file from "feature/update-ab5"
> git switch feature/update-ab6- a.txt, b.txt
-
+ab6
-
commit and push "feature/update-ab6" to origin
-
merge "develop" to "staging"
> git switch staging-
> git merge developAuto-merging a.txtCONFLICT (content): Merge conflict in a.txtAuto-merging b.txtCONFLICT (content): Merge conflict in b.txtAutomatic merge failed; fix conflicts and then commit the result.
- manual merge to a.txt, b.txt
> git commit -m "conflict merge"> git push -u origin staging
-
merge "feature/update-ab5" to "develop"
> git switch develop> git merge feature/update-ab5> git push -u origin develop
-
merge "feature/update-ab6" to "develop"
> git switch develop-
> git merge feature/update-ab6Auto-merging a.txtCONFLICT (content): Merge conflict in a.txtAuto-merging b.txtCONFLICT (content): Merge conflict in b.txtAutomatic merge failed; fix conflicts and then commit the result.
- manual merge to a.txt, b.txt
> git commit -m "conflict merge"> git push -u origin develop
-
merge "feature/update-ab6" to "staging" (cherry-pick)
> git switch feature/update-ab6-
> git logfrom "feature/update-ab6"- update ab6 : b55f83731a03421a245b3268324e90c9aa223950
> git switch staging-
> git cherry-pick b55f83731a03421a245b3268324e90c9aa223950ab6 -
git log-
+update ab6
-
> git push -u origin staging
-
merge "staging" to "main"
> git switch main> git merge staging> git push -u origin main
-
create tag "main"
> git tag -a v1.0.1 -m "bug fix ab6"> git push origin v1.0.1
-
merge "develop" to "staging"
> git switch staging-
> git merge developAuto-merging a.txtCONFLICT (content): Merge conflict in a.txtAuto-merging b.txtCONFLICT (content): Merge conflict in b.txtAutomatic merge failed; fix conflicts and then commit the result.
- manual merge to a.txt, b.txt
> git commit -m "conflict merge"> git push -u origin staging
-
merge "staging" to "main"
> git switch main> git merge staging> git push -u origin main
-
create tag "main"
> git tag -a v1.0.2 -m "bug fix ab5"> git push origin v1.0.2
-
add README.md to "develop"
> git switch develop
-
commit and push "develop" to origin
END
おわりに
読むだけじゃなくて、手を動かして体感する事って大事ですね。
参考(感謝)

