背景
Git冲突的原因,一般是修改了同一个文件导致的,这个文件有可能是别人提交到远程仓库里面,还有就是需要合并这个文件导致的。
解决方法
- 你确定你需要的是哪个仓库的文件
git checkout --theirs conflicted_file.txt # 保留远端的
git checkout --ours conflicted_file.txt # 保留本地的
- 然后执行add和commit
git add -A
git commit -m "update conflict
举个栗子
获取远端服务器上的文件,提示冲突了需要合并
# git cherry-pick FETCH_HEAD
* branch refs/changes/85/12385/3 -> FETCH_HEAD
error: 'cherry-pick' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: cherry-pick failed
查看当前仓库的状态
# git status
Not currently on any branch.
You are currently cherry-picking commit 53e5374.
(fix confli

本文介绍了Git冲突的背景,强调了解决冲突时如何选择保留远程仓库的改动。通过一个具体例子展示了当合并时遇到冲突,如何使用`git checkout --theirs`命令来将文件替换为远程仓库的版本,并进行add、commit操作,从而解决冲突。
最低0.47元/天 解锁文章
813

被折叠的 条评论
为什么被折叠?



