在远程使用了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. 然后再重新提交你的代码,就发现可以正常提交了文章来源:https://www.toymoban.com/news/detail-635794.html
文章来源地址https://www.toymoban.com/news/detail-635794.html
到了这里,关于在进行git pull操作时,存在本地文件与远程仓库发生冲突的情况的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!