![](/img/trans.png)
[英]How to checkout files from another branch and then overwrite the current branch
[英]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.