我如何在我的 Git 存储库中解决合并冲突?
当前回答
如果你经常做小承诺,然后开始看看承诺评论与 git log --merge. 然后 git diff 会向你展示冲突。
我喜欢opendiff - Git 也支持 vimdiff, gvimdiff, kdiff3, tkdiff, meld, xxdiff,从盒子中出现,你可以安装其他: git config merge.tool “your.tool” 将设置您所选择的工具,然后 git mergetool 失败的合并后将向您展示背景中的 diffs。
每当您编辑文件以解决冲突时, git 添加文件名将更新索引,而您的 diff 将不再显示。
其他回答
下面是可能的使用案例,从顶部:
你会拖一些变化,但哦,你没有到目前为止:
git fetch origin
git pull origin master
From ssh://gitosis@example.com:22/projectname
* branch master -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.
所以你更新并尝试一次,但有冲突:
git add filename.c
git commit -m "made some wild and crazy changes"
git pull origin master
From ssh://gitosis@example.com:22/projectname
* branch master -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.
所以你决定看看这些变化:
git mergetool
哦,我的,哦,我的,上流改变了一些事情,但只是用我的变化......不......他们的变化......
git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"
然后,我们试着最后一次。
git pull origin master
From ssh://gitosis@example.com:22/projectname
* branch master -> FETCH_HEAD
Already up-to-date.
是的!
查看 Stack Overflow 问题中的答案 堕胎在 Git 中的合并,特别是 Charles Bailey 的答案,显示如何查看不同版本的文件有问题,例如,
# Common base version of the file.
git show :1:some_file.cpp
# 'Ours' version of the file.
git show :2:some_file.cpp
# 'Theirs' version of the file.
git show :3:some_file.cpp
有三个步骤:
查找哪些文件导致冲突的命令 git 状态 查看文件,在其中你会发现冲突标记为 <<<<<<<头 blablabla 将其改为你想要的方式,然后与命令 git 添加解决_conflicts_files git commit -m 混合 msg
CoolAJ86的答案相当于一切. 如果您在同一代码中有两个分支的变化,您将不得不进行手动合并. 在任何文本编辑器中打开冲突中的文件,您应该看到下列结构。
(Code not in Conflict)
>>>>>>>>>>>
(first alternative for conflict starts here)
Multiple code lines here
===========
(second alternative for conflict starts here)
Multiple code lines here too
<<<<<<<<<<<
(Code not in conflict here)
选择一个替代品或两者的组合,以一种方式,你想要新的代码是,同时删除平等的标志和角膜。
git commit -a -m "commit message"
git push origin master
我正在使用Microsoft的Visual Studio代码来解决冲突. 它很容易使用. 我在工作场所保持我的项目开放. 它检测和突出冲突. 此外,它提供了GUI选项,以选择我想要从头部或进入的任何变化。
此分類上一篇
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别