错误:您对以下文件的本地更改将被签出覆盖 [英] error: Your local changes to the following files would be overwritten by checkout

查看:206
本文介绍了错误:您对以下文件的本地更改将被签出覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题类似于

This question is similar to this one, but more specific.

我有一个带有两个分支的项目: staging beta .我在 staging 上进行开发,并使用 master 分支来修复错误.因此,如果我正在暂存中并且看到错误,则更改为 master 分支:

I have a project with two branches: staging and beta. I develop on staging, and use the master branch to fix bugs. So if I'm working on staging and I see an error, I change to master branch:

git checkout master

做这些事情:

git add fileToAdd
git commit -m "bug fixed"

然后我与两个分支合并:

and then I merge with both branches:

git checkout staging
git merge master
git checkout beta
git merge beta

工作树上是否还有其他文件也没关系.

And doesn't matter if there are other files on the working tree.

但是现在,当我尝试更改为 master 分支时,出现了错误:

But now, when I try to change to the master branch, I'm getting an error:

error: Your local changes to the following files would be overwritten by checkout:
src/Pro/ConvocationBundle/Controller/DefaultController.php
Please, commit your changes or stash them before you can switch branches.
Aborting

我认为我应该从暂存区域中删除文件:

I thought that I should remove the file from the staging area:

git reset HEAD src/Pro/ConvocationBundle/Controller/DefaultController.php

但是我遇到了同样的错误.如果我执行 git status ,我将得到没有要提交的更改

but I'm getting the same error. If I do git status I get No changes to commit

推荐答案

修改文件后,要切换到的分支也对该文件进行了更改(从最新合并点开始).

Your error appears when you have modified a file and the branch that you are switching to has changes for this file too (from latest merge point).

您所看到的选项是-提交,然后用额外的更改来修改此提交(只要不进行 push 的提交,您就可以在git中修改提交);或-使用隐藏:

Your options, as I see it, are - commit, and then amend this commit with extra changes (you can modify commits in git, as long as they're not pushed); or - use stash:

git stash save your-file-name
git checkout master
# do whatever you had to do with master
git checkout staging
git stash pop

git stash save 将创建包含您所做更改的stash,但它与任何提交甚至分支都不相关. git stash pop 会将最新的stash条目应用于当前分支,还原保存的更改并将其从stash中删除.

git stash save will create stash that contains your changes, but it isn't associated with any commit or even branch. git stash pop will apply latest stash entry to your current branch, restoring saved changes and removing it from stash.

这篇关于错误:您对以下文件的本地更改将被签出覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆