Originally, the SKIP_WORKTREE bit is not removed when moving an out-of-cone file into sparse cone, thus the moved file does not show up in the working tree. Hint the user to use "git sparse-checkout reapply" to reapply the sparsity rules to the working tree, by which the SKIP_WORKTREE bit is removed. Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@xxxxxxxxx> --- I offered this solution becasue I'm not sure how to turn a cache_entry's ce_flags back to a non-sparse state. I tried directly set it to 0 like this: ce->ce_flags = 0; But the behavior after this seems undefined. The file still won't show up in the working tree. And I found that "git sparse-checkout reapply" seems to be a nice fit for the job. But I guess if there is a way (there must be but I don't know) to do it direcly in the code, that could also be nice. builtin/mv.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/mv.c b/builtin/mv.c index 9da9205e01..5f511fb8da 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -138,6 +138,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) { int i, flags, gitmodules_modified = 0; int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0; + int advise_to_reapply = 0; struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), OPT__DRY_RUN(&show_only, N_("dry run")), @@ -383,6 +384,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix) pos = cache_name_pos(src, strlen(src)); assert(pos >= 0); rename_cache_entry_at(pos, dst); + if (!advise_to_reapply && + !path_in_sparse_checkout(src, &the_index) && + path_in_sparse_checkout(dst, &the_index)) { + advise_to_reapply = 1; + } } if (gitmodules_modified) @@ -392,6 +398,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); + if (advise_to_reapply) + printf(_("Please use \"git sparse-checkout reapply\" to reapply the sparsity.\n")); + string_list_clear(&src_for_dst, 0); UNLEAK(source); UNLEAK(dest_path); -- 2.35.1