0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git cherry-pick でミスしたので、、、

Last updated at Posted at 2025-02-02

image.png

はじめに

git で cherry-pick コマンド打ったら、コンフリクトになって理由が?になりました。
忘れてるので、手を動かして思います。

develop -> staging -> main ブランチの物語

  1. create new branch "develop"

    • > git switch -c develop
  2. add new file from "develop"

    • > ni a.txt
    • + a1
  3. commit and push "develop" to origin

    • > git push -u origin develop
  4. create new branch "staging" from "develop"

    • > git switch -c staging
  5. push "staging" to origin

    • > git push -u origin staging
  6. add new file from "develop"

    • > git switch develop
    • > ni b.txt
    • + b1
  7. commit and push "develop" to origin

    • > git push -u origin develop
  8. merge "develop" to "staging"

    • > git switch staging
    • > git merge develop
    • > git push -u origin staging
  9. merge "staging" to "main"

    • > git switch main
    • > git merge staging
    • > git push -u origin main
  10. create tag "main"

    • > git tag -a v1.0 -m "first release"
    • > git push origin v1.0
  11. update file from "develop"

    • > git switch develop
    • a.txt, b.txt
    • + ab1
  12. commit and push "develop" to origin

  13. update file from "develop"

    • > git switch develop
    • a.txt, b.txt
    • + ab2
  14. commit and push "develop" to origin

  15. merge "develop" ("ab1" commit only) to "staging"

    • > git log from develop
    • update ab1 : 05810ac4784a45d48429a4b9e6edd61d23f42a6a
    • update ab2 : 10376018a0193a90b197ab5dac982ec48c53bc26
    • > git switch staging
    • > git cherry-pick 05810ac4784a45d48429a4b9e6edd61d23f42a6a
    • > git push -u origin staging
  16. update file from "develop"

    • > git switch develop
    • a.txt, b.txt
    • + ab3
  17. commit and push "develop" to origin

  18. merge "develop" ("ab3" commit only) to "staging"

    • > git log from "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 d754dd1c7bff0dc69bd12bd6f00662d43bcdf50b ab3
    • error: could not apply d754dd1... update ab3
    • hint: After resolving the conflicts, mark them with
    • ...
    • > git cherry-pick --abort (abort cherry-pick)
    • Q : why conflict
      • A : ab3 in ab2
    • > git cherry-pick 10376018a0193a90b197ab5dac982ec48c53bc26 ab2
    • > git push -u origin staging (success ab2)
  19. create "feature" branch at update file from "develop"

    • > git switch develop
    • > git switch -c feature/update-ab4
    • a.txt, b.txt
    • + ab4
  20. commit and push "feature/update-ab4" to origin

  21. merge "feature/update-ab4" to "develop"

    • > git switch develop
    • > git merge feature/update-ab4
    • > git push -u origin develop
  22. merge "feature/update-ab4" ("ab4" commit only) to "staging"

    • > git switch feature/update-ab4
    • > git log from "feature/update-ab4"
      • update ab4 : dc4ce3a3ad16b70e267b53ab1f496de34da8baa6
    • > git switch staging
    • > git cherry-pick dc4ce3a3ad16b70e267b53ab1f496de34da8baa6
      • Auto-merging a.txt
      • CONFLICT (content): Merge conflict in a.txt
      • Auto-merging b.txt
      • CONFLICT (content): Merge conflict in b.txt
      • error: could not apply dc4ce3a... update ab4
      • hint: After resolving the conflicts, mark them with
      • ...
      • > git cherry-pick --abort (abort cherry-pick)
  23. create "feature" branch at update file from "develop"

    • > git switch develop
    • > git switch -c feature/update-ab5
  24. create "feature" branch at update file from "develop"

    • > git switch develop
    • > git switch -c feature/update-ab6
  25. add "ab5" to file from "feature/update-ab5"

    • > git switch feature/update-ab5
    • a.txt, b.txt
    • + ab5
  26. commit and push "feature/update-ab5" to origin

  27. add "ab6" to file from "feature/update-ab5"

    • > git switch feature/update-ab6
    • a.txt, b.txt
    • + ab6
  28. commit and push "feature/update-ab6" to origin

  29. merge "develop" to "staging"

    • > git switch staging
    • > git merge develop
      • Auto-merging a.txt
      • CONFLICT (content): Merge conflict in a.txt
      • Auto-merging b.txt
      • CONFLICT (content): Merge conflict in b.txt
      • Automatic 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
  30. merge "feature/update-ab5" to "develop"

    • > git switch develop
    • > git merge feature/update-ab5
    • > git push -u origin develop
  31. merge "feature/update-ab6" to "develop"

    • > git switch develop
    • > git merge feature/update-ab6
      • Auto-merging a.txt
      • CONFLICT (content): Merge conflict in a.txt
      • Auto-merging b.txt
      • CONFLICT (content): Merge conflict in b.txt
      • Automatic 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
  32. merge "feature/update-ab6" to "staging" (cherry-pick)

    • > git switch feature/update-ab6
    • > git log from "feature/update-ab6"
      • update ab6 : b55f83731a03421a245b3268324e90c9aa223950
    • > git switch staging
    • > git cherry-pick b55f83731a03421a245b3268324e90c9aa223950 ab6
    • git log
      • + update ab6
    • > git push -u origin staging
  33. merge "staging" to "main"

    • > git switch main
    • > git merge staging
    • > git push -u origin main
  34. create tag "main"

    • > git tag -a v1.0.1 -m "bug fix ab6"
    • > git push origin v1.0.1
  35. merge "develop" to "staging"

    • > git switch staging
    • > git merge develop
      • Auto-merging a.txt
      • CONFLICT (content): Merge conflict in a.txt
      • Auto-merging b.txt
      • CONFLICT (content): Merge conflict in b.txt
      • Automatic 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
  36. merge "staging" to "main"

    • > git switch main
    • > git merge staging
    • > git push -u origin main
  37. create tag "main"

    • > git tag -a v1.0.2 -m "bug fix ab5"
    • > git push origin v1.0.2
  38. add README.md to "develop"

    • > git switch develop
  39. commit and push "develop" to origin

END

image.png

おわりに

読むだけじゃなくて、手を動かして体感する事って大事ですね。


参考(感謝)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?