最新消息:20181230 VPS服务器已从Linode换到腾讯云香港,主题仍用朋友推荐的大前端D8

【已解决】git pull出错:error Your local changes to the following files would be overwritten by merge

Git crifan 418浏览 0评论

一个git仓库代码,别人改动并上传了

自己此处去git pull出错:

➜  xxx git:(master) ✗ git pull

remote: Enumerating objects: 86, done.

remote: Counting objects: 100% (86/86), done.

remote: Compressing objects: 100% (60/60), done.

remote: Total 61 (delta 48), reused 0 (delta 0)

Unpacking objects: 100% (61/61), done.

From https://gitee.com/xxx/xxx

   26b05d8..20b96a1  master     -> origin/master

Updating 26b05d8..20b96a1

error: Your local changes to the following files would be overwritten by merge:

        README.md

Please commit your changes or stash them before you merge.

Aborting

看起来是

先git stash

再git pull

再git pop -》记错了,应该是:git stash pop

再去手动解决冲突

或许就可以了。

➜  xx git:(master) ✗ git stash

Saved working directory and index state WIP on master: 26b05d8 update

➜  xx git:(master) git pull

Updating 26b05d8..20b96a1

Fast-forward

README.md                                                           |  4 ++++

src/common/menu.js                                                  | 12 ++++++++++

src/common/router.js                                                |  4 ++++

src/components/GlobalHeader/index.js                                |  6 ++—

src/layouts/BasicLayout.js                                          |  7 ++++–

src/models/login.js                                                 |  1 +

src/models/user.js                                                  | 10 +++++—

src/routes/Admin/AllUserScriptCount.js                              | 15 ++++——–

src/routes/Admin/FunctionGroupCreate.js                             |  6 ++—

src/routes/Admin/{functionGroupDetail.js => FunctionGroupDetail.js} |  2 +-

src/routes/Admin/UserList.js                                        |  2 ++

src/routes/Info/UserInfo.js                                         | 61 ++++++++++++++++++++++++++++++++++++++++++++++++

src/routes/Script/GroupOwnerScriptCount.js                          | 15 ++++——–

src/routes/Script/ScriptCreate.js                                   |  6 ++++-

src/routes/Script/ScriptEdit.js                                     |  6 ++++-

15 files changed, 123 insertions(+), 34 deletions(-)

rename src/routes/Admin/{functionGroupDetail.js => FunctionGroupDetail.js} (98%)

create mode 100644 src/routes/Info/UserInfo.js

➜  NaturlingCmsWeb git:(master) git pop

git: ‘pop’ is not a git command. See ‘git –help’.

The most similar command is

        log

➜  NaturlingCmsWeb git:(master) git stash pop

Auto-merging README.md

On branch master

Your branch is up to date with ‘origin/master’.

Changes not staged for commit:

  (use "git add <file>…" to update what will be committed)

  (use "git checkout — <file>…" to discard changes in working directory)

        modified:   .webpackrc.js

        modified:   README.md

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")

Dropped refs/stash@{0} (f1fbad92e096988a23db998eb63acd97fe5e7a56)

➜  xx git:(master) ✗ git status

On branch master

Your branch is up to date with ‘origin/master’.

Changes not staged for commit:

  (use "git add <file>…" to update what will be committed)

  (use "git checkout — <file>…" to discard changes in working directory)

        modified:   .webpackrc.js

        modified:   README.md

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")

果然就可以了:

VSCode中就可以看到改动的文件和内容了:

【总结】

一个git项目,自己和别人一起协作开发。

别人先于你改动并提交了后,自己本地去:

git pull

(等价于:git fetch 再git merge)

如果出错:

error Your local changes to the following files would be overwritten by merge

原因是:

别人和你改动了同一个文件了,git的merge无法处理,所以提示你可能会被覆盖

做法是:

先去暂存自己的改动:

git stash

再去获取最新改动:

git pull

然后恢复自己本地的改动:

git stash pop

注:

如果pop后有冲突,冲突文件内部会有:

>>>

之类的标示,找到并一点点解决掉,即可。

转载请注明:在路上 » 【已解决】git pull出错:error Your local changes to the following files would be overwritten by merge

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
68 queries in 0.078 seconds, using 9.39MB memory