首页 > 解决方案 > Git 无法切换分支、存储或结帐

问题描述

我尝试将分支从 master 切换到 dev

git checkout dev
error: Your local changes to the following files would be overwritten by 
checkout:
    vendor/symfony/console/Resources/bin/hiddeninput.exe
Please, commit your changes or stash them before you can switch 
branches.
Aborting

我尝试删除更改

git checkout vendor/symfony/console/Resources/bin/hiddeninput.exe
git checkout dev
error: Your local changes to the following files would be overwritten by checkout:
vendor/symfony/console/Resources/bin/hiddeninput.exe
Please, commit your changes or stash them before you can switch branches.
Aborting

我试着藏起来

git stash
    error: Your local changes to the following files would be overwritten by checkout:
vendor/symfony/console/Resources/bin/hiddeninput.exe
Please, commit your changes or stash them before you can switch branches.
Aborting

我试着忽略它

git update-index --assume-unchanged vendor/symfony/console/Resources/bin/hiddeninput.exe
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
git checkout dev
error: Your local changes to the following files would be overwritten by checkout:
vendor/symfony/console/Resources/bin/hiddeninput.exe
Please, commit your changes or stash them before you can switch branches.
Aborting

有什么建议么?

标签: git

解决方案


不久前我遇到了类似的问题。事实证明文件的行尾自动更改(由文件中的混合行尾引起)。这可以使用 -

git config core.autocrlf

为了解决这个问题,请将 core.autocrlf 设置为 false。

git config --global core.autocrlf false

在此之后尝试执行 git checkout your-filename 。希望这可以帮助。


推荐阅读