Git

メモです(GitHubでコンフリクトが起きた)

今日の流れ

・問題
-コンフリクトが起きて、うまくマージできなかった。

一口メモ

rm <ファイル名> これで、ファイルを消せる。
git checkout -b other_branch origin/other_branch
これで、remoteにあるbranchをlocalに引っ張ってこれる。

$git rebase master
Current branch reply is up to date.

が出たので、

$git checkout master
$git pull

でmasterを更新。

$git checkout reply
して、
$git rebase master

これで、コンフリクトしているファイルにおいて、双方の変更が共存している形になった。
$git status
で状態確認(これ重要)。

XXXnoMacBook-ea:sample_app[reply *+|REBASE 3/5]$ git status
rebase in progress; onto f995345
You are currently rebasing branch 'reply' on 'f995345'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)

Changes to be committed:
(use "git reset HEAD ..." to unstage)

new file:   app/views/microposts/reply.html.erb

Unmerged paths:
(use "git reset HEAD ..." to unstage)
(use "git add ..." to mark resolution)

both modified:   app/controllers/microposts_controller.rb
both modified:   app/models/micropost.rb

これで上記2ファイルがコンフリクトしていることが確認された。

$git diff
diff --cc app/controllers/microposts_controller.rb
index cfdb2e7,13305a3..0000000
--- a/app/controllers/microposts_controller.rb
+++ b/app/controllers/microposts_controller.rb
@@@ -24,6 -24,11 +24,14 @@@ class MicropostsController < Applicatio
@microposts = Micropost.searching(params[:search])
end

++<<<<<<< HEAD
++=======
+ def reply
+ @micropost = Micropost.find(params[:micropost_id])
+ @microposts = Micropost.replying(@micropost.id)
+ end
+
++>>>>>>> create controller and view of microposts#reply
private

def micropost_params

diff --cc app/models/micropost.rb
index f6b7e05,ae47a7d..0000000
--- a/app/models/micropost.rb
+++ b/app/models/micropost.rb
@@@ -19,4 -19,10 +19,13 @@@ class Micropost < ApplicationRecor
Micropost.where(['content LIKE ?', "%#{search}%"])
end
end
++<<<<<<< HEAD
++=======
+
+ def self.replying(reply)
+ if reply
+ Micropost.where( ['reply_to = ?', reply])
+ end
+ end
++>>>>>>> create controller and view of microposts#reply
end

これでも差は確認可能。

これらをテキストエディタで直す。採用する方をUse。Useの方に新しく書き加え得ることもできる。

からの add -A

$git add -A
anzaiyuusukenoMacBook-ea:sample_app[reply +|REBASE 3/5]$ git status
rebase in progress; onto f995345
You are currently rebasing branch 'reply' on 'f995345'.
(all conflicts fixed: run "git rebase --continue")

Changes to be committed:
(use "git reset HEAD ..." to unstage)

modified:   app/controllers/microposts_controller.rb
new file:   app/views/microposts/reply.html.erb

そのあとメッセージに沿って、

$git rebase --continue

Resolve all conflicts manually, mark them as resolved with
"git add/rm ", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".

またもやファイル変更。
からの

$git add -A
anzaiyuusukenoMacBook-ea:sample_app[reply +|REBASE 5/5]$ git status
You are currently rebasing branch 'reply' on 'f995345'.
(all conflicts fixed: run "git rebase --continue")

Changes to be committed:
(use "git reset HEAD ..." to unstage)

modified:   app/controllers/microposts_controller.rb

で、またもた指示に従う。

$git rebase --continue
Applying: to resolove the conflict

[reply]$ git push --force-with-lease
Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (33/33), done.
Writing objects: 100% (33/33), 3.37 KiB | 861.00 KiB/s, done.
Total 33 (delta 21), reused 0 (delta 0)
remote: Resolving deltas: 100% (21/21), completed with 10 local objects.
To github.com:ookamiinc/rails_tutorial_app.git
+ f546dd1...8507b39 reply -> reply (forced update)
anzaiyuusukenoMacBook-ea:sample_app[reply]$