登录 主页

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

2023-08-08 02:46PM

在远程使用了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. 然后再重新提交你的代码,就发现可以正常提交了

 

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论