如何忽略Git pull上的以下错误消息?

您对以下文件的本地更改将被合并覆盖

如果我想覆盖它们怎么办?

我试过像git pull-f这样的方法,但没有任何效果。

要明确的是,我只想覆盖特定的更改,而不是所有更改。


当前回答

试试这个

git fetch --all 

git reset --hard origin/master

git pull origin master

对我来说,用力拉

其他回答

对于Pycharm,您可以执行Git-->Revert,然后执行pull。

有时,这些都不起作用。令人恼火的是,由于LF的事情,我认为,将工作的是删除文件,然后拉。我并不建议使用此解决方案,但如果文件不存在,git不会毫无用处地通知您,您的更改(甚至可能不是更改)将被覆盖,并允许您继续。

使用风险自负。

我是git新手,不确定我的解决方案是否是个好主意。

我测试了所有答案,但没有一个对我有用!

但我找到了另一个解决方案:

1. Backup both of local and repository versions of the file.
2. Delete the file from repository.
3. git add .
4. git commit
5. git push

希望这有帮助。

实例

[root@localhost www]# git pull
Username for 'http://159.65.151.11': amol
Password for 'http://amol@159.65.151.11':
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 34 (delta 13), reused 0 (delta 0)
Unpacking objects: 100% (34/34), done.
From http://159.65.151.11/OpenCC
   f793c8e..b8fe60c  v1.18.0_24Feb2022 -> origin/_v1.18.0_24Feb2022
error: Your local changes to the following files would be overwritten by merge:
        cc/routes/web.php
Please, commit your changes or stash them before you can merge.
Aborting

解决方案(忽略本地文件中已提交的更改)

git checkout HEAD^ cc/routes/web.php
git pull

好了,在其他两个答案的帮助下,我提出了一个直接的解决方案:

git checkout HEAD^ file/to/overwrite
git pull