记录 git 远程仓库中与本地同一个文件存在冲突的命令 : Your local changes to the following files would be overwritten by merg

记录 git 远程仓库中与本地同一个文件存在冲突的命令

在拉取代码后报错 : Your local changes to the following files would be overwritten by merge:

$ git pull origin master

remote: Enumerating objects: 45, done.
remote: Counting objects: 100% (45/45), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 27 (delta 17), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (27/27), 16.11 KiB | 30.00 KiB/s, done.
From gitee.com:imyar1989/dc_app
 * branch            master     -> FETCH_HEAD
   e389298..da5057a  master     -> origin/master
error: Your local changes to the following files would be overwritten by merge:
        pages/sys/device/components/module-dc.vue
Please commit your changes or stash them before you merge.
Aborting
Updating e389298..da5057a

意思是新修改的代码的文件,将会被git服务器上的代码覆盖;不想刚刚写的代码被覆盖掉,git的手册,可以这样解决:

方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

$ git stash

Saved working directory and index state WIP on master: e389298 Merge branch 'master' of gitee.com:imyar1989/dc_app
$ git pull origin master

From gitee.com:imyar1989/dc_app
 * branch            master     -> FETCH_HEAD
Updating e389298..da5057a
Fast-forward
 api/pay/index.js                              |  11 +-
 config.js                                     |   2 +-
 pages/sys/device/components/module-dc.vue     |  47 ++--
 pages/sys/device/components/module-zzj.vue    |  16 +-
 pages_device/device/components/module-dc.vue  |  12 +-
 pages_device/device/components/module-zzj.vue |   9 +-
 pages_user/iconfont/iconfont-weapp-icon.css   | 164 +++++++-----
 pages_user/memberPayment/memberPayment.vue    | 348 ++++++++++++++++++--------
 8 files changed, 413 insertions(+), 196 deletions(-)
$ git stash pop

Auto-merging pages/sys/device/components/module-dc.vue
CONFLICT (content): Merge conflict in pages/sys/device/components/module-dc.vue
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    pages/sys/device/components/module-pdc.vue
        modified:   pages/sys/device/index.vue

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   pages/sys/device/components/module-dc.vue

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        components/prompt/
        pages/sys/device/components/module-belt.vue

The stash entry is kept in case you need it again.


$ git add .

warning: in the working copy of 'components/prompt/prompt.vue', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'pages/sys/device/components/module-belt.vue', LF will be replaced by CRLF the next time Git touches it


$ git status

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   components/prompt/prompt.vue
        renamed:    pages/sys/device/components/module-pdc.vue -> pages/sys/device/components/module-belt.vue
        modified:   pages/sys/device/components/module-dc.vue
        modified:   pages/sys/device/index.vue

如此一来,服务器上的代码更新到了本地,而且你本地修改的代码也没有被覆盖,之后使用add,commit,push 命令即可更新本地代码到服务器了。

方法2、如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:

git reset --hard
git pull origin master
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值