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.
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值