如何在稀疏检出情况下进行git-rebase?

5
我有一个启用了稀疏检出的工作副本。我想要执行 git rebase -i。但是如果我在变基时遇到冲突,则所有被排除在检出之外的文件都会被标记为 deletednot staged for commit
因此,当我解决真正的冲突并 git add 所需的文件时,由于未暂存更改,我仍然无法执行 git rebase --continue。我可以执行 git checkout -f -- <excluded files>,但这非常不方便。
是否有更好的方法来使用稀疏检出进行 git-rebase
1个回答

1

我在 "Git sparse checkout with exclusion" 中提到,你现在可以使用 git sparse-checkout 命令
"现在" 意味着自 Git 2.25+(2020年第一季度)起。

而且,正如我在 "How to disable sparse checkout after enabled?" 中所记录的那样,你可以禁用/重新启用稀疏检出。

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

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.

如果出现任何问题,您可以随时切换回您的备份分支以重新开始。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接