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

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

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

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

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


当前回答

解决此问题的最佳方法是:

git checkout -- <path/file_name>

之后,您可以通过以下方式覆盖文件:

git pull origin master

其他回答

只需提交本地更改并合并提交-a

我的解决方案是从IDE外部删除将被覆盖的文件,然后进行拉取。

(您始终可以备份和手动合并未跟踪的数据)

如果使用git lfs并且文件指针被实际文件覆盖,也会出现此消息。

然后使用:

git stash
git lfs migrate import
git pull

我案子的全部结果

λ git stash
Saved working directory and index state WIP on master: 5d4ad47 Merge branch 'feature/...' into 'master'
Encountered 1 file(s) that should have been pointers, but weren't:
        public/apple-touch-icon.png

λ git pull
Updating 5a4ad44..b25f79d
error: Your local changes to the following files would be overwritten by merge:
        public/apple-touch-icon.png
Please commit your changes or stash them before you merge.
Aborting

λ git lfs migrate import
migrate: Fetching remote refs: ..., done
migrate: Sorting commits: ..., done
migrate: Rewriting commits: 100% (0/0), done
migrate: Updating refs: ..., done
migrate: checkout: ..., done


λ git pull
Updating 5d4ad47..a25c79a
Fast-forward
 public/apple-touch-icon.png | Bin 2092 -> 130 bytes
 public/favicon.ico          | Bin 6518 -> 1150 bytes
 2 files changed, 0 insertions(+), 0 deletions(-)

看见https://github.com/git-lfs/git-lfs/issues/2839

出现错误“您对以下文件的本地更改将被合并覆盖”,因为您在本地回购中有一些尚未提交的更改,因此在从远程回购中提取之前,只需提交本地回购中的更改。

假设您的远程回购有一些分支xyz并且您希望将远程repo xyz分支合并到(复制到)本地repo xyx分支,

{
git checkout xyz                  //check out to the respective branch in local repo
git commit -m "commiting message" //commit changes if any, in local repo branch xyz
git pull                          //it pulls remote xyz branch into local xyz branch
}

如果您的存储库包含一些从master中删除的文件:

切换到主分支git获取原点git reset—硬原点/主git结帐-b newbranch