by shigemk2

当面は技術的なことしか書かない

git-merge allow-unrelated-histories

git-merge allow-unrelated-histories

--allow-unrelated-histories オプションを見てみる

By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.

  • 同じ先祖じゃないブランチをマージしようとすると fatal: refusing to merge unrelated histories エラーになる
    • ブランチは通常特定のブランチから派生して作成するけど、最初のコミットが違ってて派生もしていない場合
  • 非常にレアケースなので、Gitでこのオプションを変更する設定はないし、実装する予定もない

ので、そういった場合は、 git merge --allow-unrelated-histories してやるとよい。

GitHubだと、

  1. GitHubで空のリポジトリを作る
  2. 空のリポジトリをローカルでcloneする
  3. GitHub上で、りどみなどのファイルを作成し、コミットする
  4. ローカルでファイル作成→コミット
  5. push出来ないし、pullも fatal: refusing to merge unrelated histories となる