如何通过稀疏结账进行 git-rebase?

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

我有一个启用了稀疏结帐的工作副本。我想做

git rebase -i
。但是,如果我在变基时遇到冲突,所有从签出文件中排除的文件都会标记为
deleted
not staged for commit

因此,当我解决实际冲突和

git add
所需文件时,由于未暂存的更改,我仍然无法执行
git rebase --continue
。我可以做
git checkout -f -- <excluded files>
,但是很不方便。

有没有更好的方法来

git-rebase
稀疏结账?

git git-rebase sparse-checkout
1个回答
0
投票

我在“带有排除的 Git 稀疏结账”中提到,你现在有了

git sparse-checkout
命令
我所说的“现在”是指自 Git 2.25+(2020 年第一季度)以来。

而且,正如我在“启用后如何禁用稀疏结帐?”中记录的那样,您可以禁用/重新启用稀疏结帐。

由于使用稀疏签出进行变基比较棘手(因为变基操作适用于整个历史记录,而不仅仅是工作目录中的文件),因此您可以考虑禁用/启用方法(使用比当前版本更新的 Git 版本) 2015年一):

git branch backup-branch
git sparse-checkout disable
git rebase -i <base-branch>

# Resolve them as you normally would.
# After resolving, stage the changes: 
git add <resolved-files>
git rebase --continue

# Re-enable the sparse-checkout
git sparse-checkout set <paths-or-patterns>
# Replace `<paths-or-patterns>` with the paths or patterns you had previously used.

如果出现任何问题,您可以随时切换回

backup-branch
重新开始。

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