git pull error: Your local changes to the following files would be overwritten by merge:
程序员文章站
2022-07-13 21:12:17
...
一个项目,用家里和公司两台电脑开发,比如在公司修改了如下文件:
├── a.php // 未修改
├── b.php // 修改
├── c.php // 新建
忘记提交了,然后在家修改如下文件:
├── a.php // 未修改
├── b.php // 修改
├── c.php // 新建
并提交了。第二天来到公司git pull
时候报错:
error: Your local changes to the following files would be overwritten by merge:
b.php
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
c.php
Please move or remove them before you merge.
Aborting
解决方案1:如果你想保留公司本地修改的代码,并把git服务器上的代码pull到本地(公司本地昨天修改的代码将会被暂时封存起来)
1.1代码贮藏
git stash
1.2拉取版本库代码
git pull
此时还是会报错:
error: The following untracked working tree files would be overwritten by merge:
c.php
Please move or remove them before you merge.
Aborting
因为文件c.php是新建文件,提示要把文件c.php先移走或删除,那么我们再把c.php移走,然后在拉取
Updating 9cccba7..ebfcf6d
Fast-forward
b.php | 2 +-
10 files changed, 467 insertions(+), 13 deletions(-)
create mode 100644 c.php
1.3取出贮藏,并把刚刚移走的文件移动回来
git stash pop
然后可以使用git diff -w +文件名
来确认代码自动合并的情况.
解决方案2:如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull
git reset --hard
git pull
其中git reset是针对版本,如果想针对文件回退本地修改,使用
git checkout HEAD [file]
上一篇: 安装metric-server,运行kubectl top nodes报错 Error from server (ServiceUnavailable)
下一篇: git merge 报错:error: Your local changes to the following files would be overwritten by m
推荐阅读
-
Your local changes to the following files would be overwritten by merge:
-
git 出现 error: Your local changes to the following files would be overwritten by merge
-
git pull error: Your local changes to the following files would be overwritten by merge:
-
git merge 报错:error: Your local changes to the following files would be overwritten by m
-
git 删除本地修改 Your local changes to the following files would be overwritten by merge
-
git pull 提示错误,Your local changes to the following files would be overwritten by merge
-
git:error: Your local changes to the following files would be overwritten by merge:
-
Git出现冲突error: Your local changes to the following files would be overwritten by merge
-
git pull报错:error: Your local changes to the following files would be overwritten by merge:
-
git pull 提示错误,Your local changes to the following files would be overwritten by merge