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?

More than 3 years have passed since last update.

gitで発生した問題対応から学んだことの整理

Last updated at Posted at 2021-11-11

#状況

masterは現在release分を対応します。
developでは、次のreleaseの課題に対応するために分けて対応しました。
master branchで修正が発生し、develop branchも修正が発生した状態です。
現在releaseがstoreに公開されたため、次のreleaseをmasterに合わせる必要がありました。
どちらのbranchも修正が発生したため、conflictが発生しました。
これを修正するため、develop branchから新しいbranchを作成しました。そのbranchでmasterにrebaseして、conflictを修正してmergeをしました。

#問題

修正された部分はちゃんとmasterに含まれましたが、

developbranchで修正した部分がすべてひとまとまりになり、それぞれ修正した履歴がまともに見られない状況になりました。
(-> develop branchはrebaseにしない方がいいそうです。 )

(+develop branch とmaster branch と繋がらないままコードの差分が依然として見られる異常な状況になりました。 )

#対応1 : mergeしたものを再び戻す

mergeしたものを再び戻す必要性がありました。
mergeする前の段階に戻るためには、checkoutを使用します。

Git checkout -B master 922bc3bd9

(Reset--hardと似ていますが履歴が残っているというメリットがあるようです。 Reset--soft かな? もう少し調査が必要です。)

これをそのままgitにpushしてもrejectされます。 git push -fをしてもrejectされます。

その理由はgitのprotectionのためなので、
SettingのBranchで一時的にmasterの名前を修正します。

(ex) master_tmp)

そして、再びgit push -fを実行すれば、現在のmasterが(問題のbranchを)mergeされる前の状態に戻ります。
さっき修正したmasterの名前を修正します。(master_tmp -> master)

#対応2 :master branchの変更をdevelopに取り込む
mergeしたものは戻したが、二つのBranchがconflictが出るという問題は、依然として残っています。
master branchの変更をdevelopに取り込む作業をします。

1.まず、origin/developから新しいbranchを作ります。
Git checkout -b feature/merge_master_to_develop origin/develop
2. Git merge –no -ff origin/masterを実行します。
3.conflictを修正します。
4.これをpushします。
5.gitでbase branchをdevelopに変更します。
6.変更点(Files changed)でconflictを解決した部分のみ表示されます。

まず、このprをmergeをします。(developがmasterにmergeをするのに問題がない状態にします。)

以降は簡単になります。 conflictがないdevelop branchをそのままmasterにmergeします。

  • gitでNew Pull Requestでcompare branchをdevelopに変更します。
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?