5

I have a working copy with a sparse checkout enabled. And I want to do the git rebase -i. But if I get conflict while rebasing all of the excluded from checkout files are marked as deleted and not staged for commit.

So, when I do resolve real conflicts and git add required files, I still can't do git rebase --continue due to unstaged changes. I can do git checkout -f -- <excluded files>, but it's very inconvenient.

Is there a better way to git-rebase with a sparse checkout?

abyss.7
  • 13,882
  • 11
  • 56
  • 100

1 Answers1

1

I mentioned in "Git sparse checkout with exclusion", you now have the git sparse-checkout command.
By "now", I mean since Git 2.25+ (Q1 2020).

And, as I documented in "How to disable sparse checkout after enabled?", you can disable / re-enable a sparse checkout.

Since rebasing with a sparse-checkout is tricky (because the rebase operation works on the entire history and not just the files you have in your working directory), you can consider that disable/enable approach (with a more recent Git version than the 2015 one):

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.

If anything goes wrong, you can always switch back to your backup-branch to start over.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250