Git:代码冲突常见解决方法[通俗易懂]

Git:代码冲突常见解决方法[通俗易懂]Git:代码冲突常见解决方法

大家好,又见面了,我是你们的朋友全栈君。

1,问题:
error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge.

解决:
(1):如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stash
git pull
git stash pop

然后可以使用git diff -w +文件名 来确认代码自动合并的情况.

(2):希望用代码库中的文件完全覆盖本地工作版本. 方法如下

git log
git reset --hard
git pull

2,问题:
error: The following untracked working tree files would be overwritten by merge:
composer.lock
Please move or remove them before you merge.
Aborting

如果确定使用云端的代码,最方便的解决方法是删除本地修改,可以使用以下命令:

git clean  -d  -fx ""
d  -----删除未被添加到git的路径中的文件
f  -----强制运行
x  -----删除忽略文件已经对git来说不识别的文件

git clean 参数 
-n 显示 将要 删除的 文件 和 目录 
-f 删除 文件,-df 删除 文件 和 目录

# 在用上述 git clean 前,墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删
git clean -nxfd
git clean -nf
git clean -nfd

3,问题
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use ‘git add/rm ’
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
解决

pull会使用git merge导致冲突,需要将冲突的文件resolve掉 git add -u, git commit之后才能成功pull.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/105922.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号