Sparse-checkout excluded files show as deleted in git status after some operations
- From
- Ross Allan <ross@nallar.me>
- Date
- Apr 6, 2017, 16:39 UTC
- Message-ID
- <CABZvOEps9HvViW2bKXEUtTbzy1+UbtM_2muBBycDSwBXOTtF7Q@mail.gmail.com>
Hi,
Sometimes when working on a repository with files excluded using the sparse checkout feature, the skip-worktree flag is incorrectly unset causing files to show as deleted in git status.
Initially I reported this to git-for-windows at https://github.com/git-for-windows/git/issues/811 but was recommended to go here as it is not a windows specific issue (my mistake there).
It has happened a few times when merging and cherry picking. Here is an example repository which can be used to demonstrate the issue: https://github.com/nallar/git-issue-sparse-checkout
The following commands run into the issue.
git clone https://github.com/nallar/git-issue-sparse-checkout.git mcve-sparse-checkout cd mcve-sparse-checkout git config core.sparseCheckout true cp sparse-checkout .git/info/sparse-checkout git checkout -f master git reset --hard HEAD # We now have sparse checkout enabled, so the folder "excluded-folder" should not be present ls # We should have no changes so far git status # Cherry-pick top commit from the other branch git cherry-pick other # That cherry-pick succeeded with no conflicts. We should have no unstaged changes git status # Oh dear, now it shows 'deleted: excluded-folder/1.txt' # Workaround, set skip-worktree which for some reason got unset: git update-index --skip-worktree excluded-folder/1.txt # Now it's showing the correct result again git status # no changes
Full log demonstrating issue: https://gist.github.com/anonymous/e1e29f0eb9df25b506fdf555827c73ac
Thanks Ross Allan