最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]git pull时出错:Your local changes to the following files would be overwritten by merge

Git crifan 5398浏览 0评论
brancepengdeMacBook-Pro:iOS-Client minglong$ git pull
Username for ‘http://git.oschina.net’: [email protected]
Password for ‘http://[email protected]@git.oschina.net’:
remote: Counting objects: 25, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 25 (delta 15), reused 0 (delta 0)
Unpacking objects: 100% (25/25), done.
From http://git.oschina.net/windoze/iOS-Client
   dec7330..c99180f  master     -> origin/master
   f0edd68..c99180f  remote_push -> origin/remote_push
* [new tag]         remote_push -> remote_push
Updating dec7330..c99180f
error: Your local changes to the following files would be overwritten by merge:
        JianDao/JianDao/Constants.swift
Please, commit your changes or stash them before you can merge.
Aborting

搜:

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

参考:

Git:代码冲突常见解决方法 – 陈小峰-iefreer的专栏 – 博客频道 – CSDN.NET

解决git pull时出现的几个问题 – ritto’s blog – 51CTO技术博客

关于git pull的问题,如何在不commit的前提下pull回来? – Git – 知乎

通过:

git stash –help

看到帮助文档:

GIT-STASH(1)                                     Git Manual                                     GIT-STASH(1)
NAME
       git-stash – Stash the changes in a dirty working directory away
SYNOPSIS
       git stash list [<options>]
       git stash show [<stash>]
       git stash drop [-q|–quiet] [<stash>]
       git stash ( pop | apply ) [–index] [-q|–quiet] [<stash>]
       git stash branch <branchname> [<stash>]
       git stash [save [-p|–patch] [-k|–[no-]keep-index] [-q|–quiet]
                    [-u|–include-untracked] [-a|–all] [<message>]]
       git stash clear
       git stash create [<message>]
       git stash store [-m|–message <message>] [-q|–quiet] <commit>
DESCRIPTION
       Use git stash when you want to record the current state of the working directory and the index, but
       want to go back to a clean working directory. The command saves your local modifications away and
       reverts the working directory to match the HEAD commit.
       The modifications stashed away by this command can be listed with git stash list, inspected with git
       stash show, and restored (potentially on top of a different commit) with git stash apply. Calling git
       stash without any arguments is equivalent to git stash save. A stash is by default listed as "WIP on
       branchname …", but you can give a more descriptive message on the command line when you create one.
       The latest stash you created is stored in refs/stash; older stashes are found in the reflog of this
       reference and can be named using the usual reflog syntax (e.g. stash@{0} is the most recently created
       stash, stash@{1} is the one before it, stash@{2.hours.ago} is also possible).
OPTIONS
       save [-p|–patch] [-k|–[no-]keep-index] [-u|–include-untracked] [-a|–all] [-q|–quiet] [<message>]
           Save your local modifications to a new stash, and run git reset –hard to revert them. The
           <message> part is optional and gives the description along with the stashed state. For quickly
           making a snapshot, you can omit both "save" and <message>, but giving only <message> does not
           trigger this action to prevent a misspelled subcommand from making an unwanted stash.
           If the –keep-index option is used, all changes already added to the index are left intact.
           If the –include-untracked option is used, all untracked files are also stashed and then cleaned
           up with git clean, leaving the working directory in a very clean state. If the –all option is
           used instead then the ignored files are stashed and cleaned in addition to the untracked files.
           With –patch, you can interactively select hunks from the diff between HEAD and the working tree
           to be stashed. The stash entry is constructed such that its index state is the same as the index
:

stash用于保存当前的状态

git stash

git pull

git stash pop

然后给出之前的使用的效果:

licrifandeMacBook-Pro:iOS-Client crifan$ git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use "git reset HEAD <file>…" to unstage)
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/bubble_receive.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/bubble_send.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
new file:   JianDao/NormalTextField.swift
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:   JianDao/CrifanLib.swift
modified:   JianDao/JianDao.xcodeproj/project.pbxproj
modified:   JianDao/NormalTextField.swift
licrifandeMacBook-Pro:iOS-Client crifan$ git stash
Saved working directory and index state WIP on master: b2ab3fd update register UI and forgot password UI
HEAD is now at b2ab3fd update register UI and forgot password UI
licrifandeMacBook-Pro:iOS-Client crifan$ git pull
Already up-to-date.
licrifandeMacBook-Pro:iOS-Client crifan$ git stash pop
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use "git reset HEAD <file>…" to unstage)
new file:   JianDao/NormalTextField.swift
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:   JianDao/CrifanLib.swift
modified:   JianDao/JianDao.xcodeproj/project.pbxproj
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/bubble_receive.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/bubble_send.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
Dropped refs/stash@{0} (f5cb85b5796046fefb430a6cdad3b71dd3b153c2)
licrifandeMacBook-Pro:iOS-Client crifan$ git stash
Saved working directory and index state WIP on master: b2ab3fd update register UI and forgot password UI
HEAD is now at b2ab3fd update register UI and forgot password UI
licrifandeMacBook-Pro:iOS-Client crifan$ git pull
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 13), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
   b2ab3fd..9096256  master     -> origin/master
Updating b2ab3fd..9096256
Fast-forward
 JianDao/AddMoreView.swift                                                    |  45 ++++++++++++++++++++++++++++<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #c33720;"–<——
 …/NavigationBar/navi_down.imageset/navi_switch_team_down.png               | Bin 981 -> 995 bytes
 …/NavigationBar/navi_down.imageset/[email protected]            | Bin 1046 -> 1001 bytes
 …/NavigationBar/navi_down.imageset/[email protected]            | Bin 1116 -> 1127 bytes
 JianDao/JianDao/Constants.swift                                              |   4 ++<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #c33720;"–<
 JianDao/MainViewController.swift                                             |   8 +++<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #c33720;"–<–
 JianDao/SwitchTeamTableView.swift                                            |   1 +
 JianDao/TeamTableViewData.swift                                              |  10 ++++<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #c33720;"–<–
 8 files changed, 48 insertions(+), 20 deletions(-)
licrifandeMacBook-Pro:iOS-Client crifan$ git stash pop
Auto-merging JianDao/JianDao/Constants.swift
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use "git reset HEAD <file>…" to unstage)
new file:   JianDao/NormalTextField.swift
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:   JianDao/CrifanLib.swift
modified:   JianDao/GlobalValues.swift
modified:   JianDao/JianDao.xcodeproj/project.pbxproj
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/bubble_receive.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_receive.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/bubble_send.png
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/Conversation/bubble_send.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/NavigationBar/navi_back.imageset/navi_back.png
modified:   JianDao/JianDao/Assets.xcassets/NavigationBar/navi_back.imageset/[email protected]
modified:   JianDao/JianDao/Assets.xcassets/NavigationBar/navi_back.imageset/[email protected]
modified:   JianDao/JianDao/Constants.swift
modified:   JianDao/LoginViewController.swift
modified:   JianDao/MessageTableViewController.swift
modified:   JianDao/RegisterPhoneViewController.swift
Dropped refs/stash@{0} (263fc50f4e69f85e9c0c2ffb7926d2942ac3d7ee)
licrifandeMacBook-Pro:iOS-Client crifan$

可以看到:

当用

git stash pop

去恢复之前本地的修改时,

如果有内容需要合并(有部分文件同时被本地修改和最新服务器的修改)

则git会自动帮你合并merge:

Auto-merging JianDao/JianDao/Constants.swift

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

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. force git pull to overwrite local files git fetch --all git reset --hard origin/master Source - https://code.askmein.com/git-pull-force-to-overwrite-local-files/
    Askmein6年前 (2018-09-22)回复
88 queries in 0.141 seconds, using 22.13MB memory