【Git】fatal: Exiting because of an unresolved conflict の解決法
この記事の概要
Git でプロジェクトをpushしようとしたらfatal: Exiting because of an unresolved conflict.というエラーが発生したので、このエラーの解決法を調べて自分なりにまとめてみました。
目次
- この記事の概要
 - 目次
 - 環境
 - やろうとしたこと
 - 対処法
 - まとめ
 
環境
・mac OS Catarina バージョン10.15.1(2017モデル)
・Rails 6
・heroku
やろうとしたこと
GitHubに修正したリポジトリの内容を、プルしようとした。
master ブランチ
$ git pull origin master
ここまでは、特に問題がない。
が、
    error: Pulling is not possible because you have unmerged files.
    hint: Fix them up in the work tree, and then use 'git add/rm <file>'
    hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.というエラーが現れて、先に進めない。
git初心者なので、mergeをしたり、revertをしたり、色々と試してみたものの、うまくいかない...。
Tips: ちなみに、
$ git log --oneline --graph --allで 、ブランチの一覧を取得できる。
すると、aブランチとbブランチの間でいつの間にかブランチが枝分かれしていることがわかった。
以下:解決策
① master をpullする
% git pull origin master   
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
② git statusで状況を確認する
% git status            
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)
③この赤いところを確認する
Changes to be committed:
 modified:   app/views/layouts/application.html.erb
Unmerged paths:
  (use "git add <file>..." to mark resolution)
 both modified:   app/assets/stylesheets/home.scss
④赤いファイルをaddして、commit
% git add  app/assets/stylesheets/home.scss
% git commit -m " app/assets/stylesheets/home.scss"
[master 3f52760]  app/assets/stylesheets/home.scss
⑤ git statusで状況を確認する
% git status                                       
On branch master
nothing to commit, working tree clean
無事にコミットできました。
まとめ
git初心者の方は、いきなりこのエラーが出たら焦ると思うが、深呼吸。
結局のところ、ひとつひとつ原因を特定して潰していくしかない。
コメント
コメントを投稿