gitでconflictしたら、conflictしたファイルを修正する。
次にStaging areaに修正したファイルを上げた後にコミットすること。
mainブランチとconflictブランチの2つのブランチでそれぞれファイルを変更する。
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git add README.md
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git commit -m "conflict-test"
[conflict 94856b0] conflict-test
1 file changed, 1 insertion(+), 1 deletion(-)
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git status
On branch conflict
nothing to commit, working tree clean
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git log --oneline
94856b0 (HEAD -> conflict) conflict-test
2316fc2 (origin/main, origin/HEAD, main) Update README.md
8b30521 (tag: v1.0.0, a) new file
4f93311 delete file
83ff903 make new file
1a83ddd change name
7fc4362 add newfile
b52de06 Initial commit
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ cat README.md
# git-practice
このリポジトリはGit動画講座用です.
変更
github上で更新0629
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git add README.md
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git commit -m "update"
[main 0f9408b] update
1 file changed, 1 insertion(+), 1 deletion(-)
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git log
commit 0f9408b1bcdce0eaa5368e2b4a3947f71d3c78cd (HEAD -> main)
Author: 〇〇〇〇 <〇〇〇〇@gmail.com>
Date: Thu Jun 29 13:56:16 2023 +0900
update
ブランチ同士の「git diff」を見る。
そして、「git merge」するとconflictになる。
「git merge conflict」で、指定したconflictブランチを今いるmainブランチにマージする。
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git diff main conflict
diff --git a/README.md b/README.md
index fa9fa0e..9668644 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
# git-practice
このリポジトリはGit動画講座用です.
変更
-github上で更新0629(mainブランチで変更)
+conflictの対処の練習github上で更新0629(conflictより)
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git merge conflict
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ ls -a
./ ../ .git/ README.md delete_soon.txt namechangee2.txt
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ git log
commit 0f9408b1bcdce0eaa5368e2b4a3947f71d3c78cd (HEAD -> main)
Author: 〇〇〇〇 <〇〇〇〇@gmail.com>
Date: Thu Jun 29 13:56:16 2023 +0900
update
README.mdファイルを編集する。
README.mdを修正後にstaging areaに上げて、コミットする。
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ git add README.md
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: README.md
△△△@B-7-PC MINGW64 ~/git-practice (main|MERGING)
$ git commit -m "resolve conflict"
[main 7675a82] resolve conflict
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
△△△@B-7-PC MINGW64 ~/git-practice (main)
$
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ git log --oneline --graph
* 7675a82 (HEAD -> main) resolve conflict
|\
| * 94856b0 (conflict) conflict-test
* | 0f9408b update
|/
* 2316fc2 (origin/main, origin/HEAD) Update README.md
* 8b30521 (tag: v1.0.0, a) new file
* 4f93311 delete file
* 83ff903 make new file
* 1a83ddd change name
* 7fc4362 add newfile
* b52de06 Initial commit
daiki@B-7-PC MINGW64 ~/git-practice (main)
$ cat README.md
# git-practice
このリポジトリはGit動画講座用です.
変更
conflictの対処の練習github上で更新0629(conflictより)
daiki@B-7-PC MINGW64 ~/git-practice (main)
$
△△△@B-7-PC MINGW64 ~/git-practice (main)
$ cat README.md
# git-practice
このリポジトリはGit動画講座用です.
変更
conflictの対処の練習github上で更新0629(conflictより)
conflictブランチに移動してlogを表示してみる。
△△△@B-7-PC MINGW64 ~/git-practice (conflict)
$ git log --oneline --graph
* 94856b0 (HEAD -> conflict) conflict-test
* 2316fc2 (origin/main, origin/HEAD) Update README.md
* 8b30521 (tag: v1.0.0, a) new file
* 4f93311 delete file
* 83ff903 make new file
* 1a83ddd change name
* 7fc4362 add newfile
* b52de06 Initial commit
関連
【Git】指定したブランチを今いるブランチにマージする (attacktube.com)