reset: unstage empty deleted ita files
diff mbox series

Message ID
State New
Headers show
  • reset: unstage empty deleted ita files
Related show

Commit Message

Varun Naik July 12, 2019, 3:02 p.m. UTC
It is possible to delete a committed file from the index and then add it
as intent-to-add. After `git reset HEAD`, the file should be identical
in the index and HEAD. This patch provides the desired behavior even
when the file is empty in the index.

Signed-off-by: Varun Naik <>
My first patch!

According to an old thread on the mailing list[0], this issue is known,
but it looks like people overlooked the fix that I'm making. Basically,
this one line causes diff-lib.c:do_oneway_diff() to call show_modified()
instead of diff_index_show_file() for ita files.

An alternative to the last line of the test code is running `git status
--porcelain=v2` and then inspecting the output. I can adjust that if

Unfortunately, "restore" has a similar problem, but it follows a
different code path into read-cache.c rather than diff-lib.c, and there
does not seem to be a similar one-line fix.


 builtin/reset.c  |  1 +
 t/ | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff mbox series

diff --git a/builtin/reset.c b/builtin/reset.c
index 26ef9a7bd0..47a088f4b7 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -163,6 +163,7 @@  static int read_from_tree(const struct pathspec *pathspec,
 	opt.format_callback_data = &intent_to_add;
 	opt.flags.override_submodule_config = 1;
 	opt.repo = the_repository;
+	opt.ita_invisible_in_index = 1;
 	if (do_diff_cache(tree_oid, &opt))
 		return 1;
diff --git a/t/ b/t/
index 97be0d968d..250fc1c890 100755
--- a/t/
+++ b/t/
@@ -566,4 +566,15 @@  test_expect_success 'reset --mixed sets up work tree' '
 	test_must_be_empty actual
+test_expect_success 'reset --mixed removes deleted intent-to-add file from index' '
+	echo "nonempty" >nonempty &&
+	>empty &&
+	git add nonempty empty &&
+	git commit -m "create files to be deleted" &&
+	git rm --cached nonempty empty &&
+	git add -N nonempty empty &&
+	git reset HEAD nonempty empty &&
+	git diff --staged --exit-code