4

在我进行了一些更改branch1并提交之后,我正在尝试结帐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"

4

2 回答 2

2

解决如下:

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

.gitignore 出现在 No staged for commit files

>>git checkout -- .gitignore
于 2018-08-20T09:40:38.973 回答
0

如果您需要签出 branch2 忽略对 branch1 所做的更改

首先重置在 branch1 上所做的更改

git reset --hard

然后结帐 branch2

git checkout branch2

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

于 2018-09-11T10:31:44.467 回答