Git merge 解决冲突

如何在命令行用 git mergetool  处理冲突

  • git merge git checkout -b about master

  • 编辑about.html git add about.html git commit -m "add about.html " git branch about2 about

  • 编辑about.html git commit -m "add about.html 1" -a git checkout about2

  • 编辑about.html git commit -m "add about.html 2" -a git checkout about git merge about2 git mergetool git commit

  • 处理冲突软件(kdiff3):git config --global merge.tool kdiff3

  • git mergetool
~$ git status
On branch about2
Your branch is up to date with 'origin/about2'.

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:   about.md

no changes added to commit (use "git add" and/or "git commit -a")
~$ git mergediff
git: 'mergediff' is not a git command. See 'git --help'.

The most similar command is
	merge-file
~$ git mergetool
Merging:
about.md

Normal merge conflict for 'about.md':
  {local}: modified file
  {remote}: modified file
merge of about.md failed
~$ git mergetool
Merging:
about.md

Normal merge conflict for 'about.md':
  {local}: modified file
  {remote}: modified file
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.

相关的软件是BeyondCompare

Git merge 解决冲突_git


解决完冲突 commit 再push即可

~$ git push 
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 10 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 323 bytes | 323.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:appinn/gittest.git
   4ff9bbb..2b2e645  about2 -> about2
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.


当目录merge出现confilct时

可以使用git ls-files -s查看当前staged的object的状态

可以看到test文件出现了3个stage的状态,分别为1,2,3。

而没有出现冲突的文件的stage状态为0.

针对存在confilict的文件可以:

git show :1:test # 查看冲突文件的common ancester版本

git show :2:test # 查看本地branch中的版本

git show :3:test # 查看远程branch中的版本

参考文档:

 https://www.yiibai.com/git/git_mergetool.html


var code = "e0ea7a64-1f59-4757-9926-1638d0410399"
  • 1.
posted @ 2023-10-05 21:01  Appinn  阅读(24)  评论(0编辑  收藏  举报  来源