在进行git pull操作时,存在本地文件与远程仓库发生冲突的情况

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

在远程使用了git pull origin main:main命令后出现下面的错误

# git pull origin main:main
Password for 'https://347340@github.com':
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 4), reused 6 (delta 4), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/347340/blog
   be6f3ac..b25ae08  main       -> main
   be6f3ac..b25ae08  main       -> origin/main
warning: fetch updated the current branch head.
fast-forwarding your working tree from
commit be6f3ac9953448f26b1745b6be8dd20a32560126.
error: Your local changes to the following files would be overwritten by merge:
	app/views/articles/show.html.erb
Please commit your changes or stash them before you merge.
Aborting
fatal: Cannot fast-forward your working tree.
After making sure that you saved anything precious from
$ git diff be6f3ac9953448f26b1745b6be8dd20a32560126
output, run
$ git reset --hard
to recover.

1. 本地仓库所在的目录下先保存本地修改

2. 执行这个命令来清除本地修改并回退到与远程仓库一致的状态

git reset --hard

这个命令会删除所有未提交的修改所以在执行这个命令之前先保存对本地的修改。

3.  然后再执行git pull origin main:main 命令来拉取远程仓库的最新代码这会将远程仓库的main分支合并到本地的main分支。

4. 然后再重新提交你的代码就发现可以正常提交了

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6