0
1

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 1 year has passed since last update.

Git でコンフリクトが出たときの「現在の変更」と「入力側の変更」の見分け方

Last updated at Posted at 2023-03-12

git merge ブランチ名でコンフリクトが出たときは、VSCode上でコンフリクトが発生しているファイルの中のコンフリクト箇所が表示されます。
image.png
自分の場合ですが、「現在の変更」と「入力側の変更」がどちらがどちらかわかりにくかったので、見分け方をまとめました。
ちなみに誤って違う方を取り込んでしまった場合はcommand + Zで取り込み前の状態(上の画像)に戻せます。

前提

以下の状況でコンフリクトが発生しました。

$ git status
On branch users
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   app/controllers/users_controller.rb
	modified:   app/models/user.rb
	modified:   app/views/layouts/application.html.erb
	modified:   app/views/users/new.html.erb
	modified:   app/views/users/show.html.erb
	modified:   config/routes.rb

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	app/views/users/edit.html.erb

no changes added to commit (use "git add" and/or "git commit -a")
$ git add -A
$ git commit -m "ユーザー情報の編集機能を実装"
[users 2c6873d] ユーザー情報の編集機能を実装
 7 files changed, 49 insertions(+), 9 deletions(-)
 create mode 100644 app/views/users/edit.html.erb
$ git status
On branch users
nothing to commit, working tree clean
$ git branch 
  anything
  growth-diary
  jobs
  main
* users
$ git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
$ git merge users
Auto-merging config/routes.rb
Auto-merging app/views/layouts/application.html.erb
CONFLICT (content): Merge conflict in app/views/layouts/application.html.erb
Automatic merge failed; fix conflicts and then commit the result.

mainブランチでのapplication.html.erbの状態

<!DOCTYPE html>
<html>
  <head>
    <title>AgriApp</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
    <%= javascript_importmap_tags %>
  </head>

  <body>







    <% if flash[:notice] %>
      <div class="flash">
        <%= flash[:notice] %>
      </div>
    <% end %>
    <%= yield %>
  </body>
</html>

usersブランチでのapplication.html.erbの状態

<!DOCTYPE html>
<html>
  <head>
    <title>AgriApp</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
    <%= javascript_importmap_tags %>
  </head>

  <body>
    <header>
      <li>
        <%= link_to("お仕事一覧", "/jobs/index") %>
      </li>
      <li>
        <%= link_to("新規登録", "/signup") %>
      </li>
    </header>

    <% if flash[:notice] %>
        <%= flash[:notice] %>
    <% end %>
    <%= yield %>
  </body>
</html>
  • 「現在の変更」を取り込んだ場合
    image.png

  • 「入力側の変更」を取り込んだ場合
    image.png

  • 「両方の変更」を取り込んだ場合
    image.png

  • 「変更の比較」
    image.png

現在の変更:
git merge ブランチ名ブランチ名での状態を取り込むことを意味する

入力側の変更
git merge ブランチ名を実行したブランチでの状態を取り込むこと意味する

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?