3
1

More than 3 years have passed since last update.

Git で履歴を保ったまま Mono-repository に merge in する

Posted at

monorepo に subrepo をマージ in する方法

monorepo 内での位置を決めておく

まず初めに、monorepo 内での subrepo のディレクトリを決めておく必要がある。

ここに移動したらすぐに動くはず、というのが決まっているなら、シンプルにそこを指定すれば良い。
例えば subrepo -> monorepo/library/subrepo 等になるパターン。

そうで無い場合、一旦 monorepo/temp/subrepo としてマージして、その後、順次 temp/subrepo 内のファイルを編集・各ディレクトリに移動すればよい。

まずは全てのファイルを同時に temp/xxxx にマージする のが大事。

subrepo を monorepo にマージする

以下を monorepo 側で実施

git remote add subrepo {subrepo ディレクトリへのパス}
git fetch --all

特にリモートを指定する必要は無いので、subrepo はローカルディレクトリで良い

subtree merge する

https://docs.github.com/en/free-pro-team@latest/github/using-git/about-git-subtree-merges
ここに書いてある事をそのままやればよい。

git merge subrepo/master --allow-unrelated-histories  -s ours --no-commit
git read-tree --prefix=temp/subrepo -u subrepo/master
git commit -m "Subtree merged subrepo into temp/subrepo"

このとき --allow-unrelated-histories を指定しないと fatal: refusing to merge unrelated histories で失敗する。

お好みでやっても良いこと

無駄なバイナリ履歴を削ぎ落とす

既に使われていないバイナリで、過去の履歴に残存しているものが無駄な場合、このタイミングで git-lfs に変換するとよい。

(これは追加作業でミスの恐れもあるため、移動の一環としてしれっとやるのはやめて、メンバーと相談すると良い。)

必要があれば https://github.com/git-lfs/git-lfs/blob/master/docs/man/git-lfs-migrate.1.ronn を確認して作業する。

etc. (何か思いついたら書く)

3
1
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
3
1