“错误:以下未跟踪的工作树文件将被签出覆盖”,但远程分支已合并

问题描述 投票:0回答:1

我正在一个本地分支上工作,在拉取请求获得批准后,该分支的远程版本已被合并。合并后,该分支的远程版本随后被删除。所以这个分支只存在于我本地。

但是,我现在无法退出分支,因为当我尝试

git checkout main
时,我收到错误
error: The following untracked working tree files would be overwritten by checkout:
,其中包含我不关心的文件列表。

解决方案的所有变体

git add *
git stash
git pull

git pull
上失败并显示错误消息

Your configuration specifies to merge with the ref 'refs/heads/mybranchname'
from the remote, but no such ref was fetched.

因为远程版本已经不存在了。我不想这样做

git clean
因为我的本地目录中有一些我关心的未跟踪文件。帮助!怎样才能摆脱困境?

git
1个回答
0
投票

要忽略“覆盖”错误,如果您确实不关心列出的文件,只需使用

git checkout -f main
即可。它们将被
main
中的版本覆盖,不会出现错误或警告。

另一种完全不推荐的选择是先将这些文件的模式写入 gitignore(如

.gitginore
.git/info/exclude
),然后运行
git checkout main

git pull
已扩展为
git pull origin $currentbranch
$currentbranch
已从远程存储库中删除。如果分支已被 PR 合并到
main
,您可以使用
git pull origin main
git pull origin -r master
(推荐,以防本地分支中有任何新提交)。

© www.soinside.com 2019 - 2024. All rights reserved.