繁体   English   中英

如何结帐到另一个分支并强制覆盖更改

[英]How to checkout to another branch and forcibly overwrite changes

在我对branch1做了一些更改并branch1它们后,我正在尝试checkout到branch2

>>git checkout branch2
error: Your local changes to the following files would be overwritten by checkout:
    .gitignore
Please, commit your changes or stash them before you can switch branches.
Aborting

但是我没有看到更新文件中提到的.gitignore文件:

>>git status
On branch branch1
Your branch is ahead of 'origin/branch1' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean
>>git stash 
No local changes to save

我也试过了

>>git checkout branch2 -f

但得到了

error: Entry '.gitignore' not uptodate. Cannot merge.

>>git rm --cached .gitignore

没有成功

我如何强行结帐到branch2忽略这个"error: Your local changes to the following files would be overwritten by checkout"

解决方法如下:

>>git rm --cached .gitignore
>>git reset HEAD /path/to/.gitignore

.gitignore出现在No staged for commit files中

>>git checkout -- .gitignore

如果你需要的是checkout branch2忽略在branch1上完成的更改

首先重置在branch1上完成的更改

git reset --hard

然后结帐branch2

git checkout branch2

希望这可以帮助.... :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM