簡體   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