[Git] git pull冲突和git stash pop冲突解决

本文介绍了两种解决Git中pull操作导致的代码冲突的方法:一种是通过暂存本地修改后pull,然后解决冲突;另一种是撤销所有本地修改后直接pull。此外,还详细说明了如何处理stash pop时遇到的冲突。

一、git pull 冲突

代码仓有人提交了新代码,而我本地也修改了代码,想要pull一下,却发现:

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

百度了一下解决办法很简单,有两种:

  1. 暂存本地的修改,pull之后解决冲突
  2. 撤销本地所有的修改,再pull

第一种办法:暂存本地的修改,pull之后解决冲突

git stash
git pull
git stash pop

如果 git stash pop 遇见冲突,请见后文 git stash pop 冲突

第二种办法:撤销本地所有的修改

git reset --hard
git pull

二、git stash pop 冲突

git stash和git pull之后,想要git stash pop,却报错:

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

报错原因:对 git pull 之后的代码有修改。

$ git status
	...
        modified:   test.txt
        modified:   work/workspace.xml
        modified:   work/ssss
        modified:   work/aaa
		...

$ git checkout .	# 撤销git pull之后的所有修改
# $ git checkout -- test.txt	 # 撤销test.txt的修改
# $ git checkout -- work/		 # 撤销work/目录下所有文件的修改


$ git statsh pop
Auto-merging user/views.py
CONFLICT (content): Merge conflict in user/views.py
The stash entry is kept in case you need it again.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值