LoginSignup
1
0

More than 1 year has passed since last update.

Conflict

branch間の相容れない変更によってconflictが生じます。
↓ Githubだとこんな感じです。
スクリーンショット 2022-11-23 14.07.54.png

解消法(ローカルリポジトリで修正する)

※masterブランチとconflictを起こしているものとして進めます。

  1. まずは落ち着きましょう。初めて遭遇した時はちょっとびっくりして汗をかくと思うので、汗を拭きましょう。

  2. masterブランチに移動して、masterブランチを最新の状態にします。git pull origin master
    ↑ conflictが起きているリモートブランチと同じ状態を作るため

  3. 作業ブランチに移動して、git rebase master
    => ローカルリポジトリで同様のコンフリクトが起こります。

  4. conflictを解消できる状況になるので、解消します(いらないところは消して、必要なところは残す)。

  5. 解消したらgit add .してgit rebase --continueします。
    https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---continue

  6. 完了したら、pushします。(この場合、force pushする必要があります。)

rebase後のpush

コミットをまとめた後など、rebase後にpushをする際にはforce pushをする必要があります。
普通にpushをしようとすると下記のようなエラーがでます。

     ! [rejected]        develop -> develop (non-fast-forward)
    error: failed to push some refs to 'https://github.com/url'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

エラー文に書いてあるように、原因はnon-fast-forwardだからです。

pushはfast forwardを前提としています。
つまり、プルリクエストの最後のコミットハッシュが親コミットになるようなコミットハッシュしかpushすることができないということです。

ただ、force pushは割と危険なので気をつけて使いましょう。

参考にしたサイト

終わりに

gitは「習うより慣れよ」だと思います。
練習用のリポジトリを作って、繰り返し練習しましょう!!

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