【Git】Please commit your changes or stash them before you merge的解决方法

背景

我从远程库中clone了一个项目进行开发,修改了一部分代码后,远程库有更新,我想将远程更新拉取下来,并且保留自己的更改,使用git pull origin master命令,有报错:

error: Your local changes to the following files would be overwritten by merge:
        xxx/xxx/api.py
        xxx/xxx/settings.py
        xxx/package.json
Please commit your changes or stash them before you merge.
Aborting
Updating 58b3d95..c5b6724

解决方法

使用git stash

官方的介绍
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the command.git stash
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).
通常,当您处理项目的一部分时,事情处于混乱状态,您希望切换分支以处理其他事情。 问题是,你不想做一个半成品的工作提交,以便稍后可以回到这一点。 这个问题的答案是命令。git stash
存储获取工作目录的脏状态(即修改的跟踪文件和暂存更改),并将其保存在一堆未完成的更改中,您可以随时重新应用这些更改(甚至在不同的分支上)。

步骤如下:

要将新的存储推送到堆栈上
> git stash
Saved working directory and index state WIP on master: 58b3d95 修改README文件
把远程仓库的更新拉到本地仓库中
> git pull
把刚才存储推送到堆栈上的代码更新到本地
> git stash pop

参考链接

你可能感兴趣的:(大橙子用Github,git)