There are some index handling subtleties in 'commit --only' that are
best tested when we have an existing index, but an unborn or empty
HEAD.  These circumstances are easily produced by 'checkout --orphan',
but we did not previously have a test for it.

The main expected failure mode would be: erroneously loading the
existing index contents when building the temporary index that is used
for --only.  Cf.

and subsequent discussion.

Signed-off-by: Thomas Rast <>
 t/ | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/t/ b/t/
index 195e747..99ce36f 100755
--- a/t/
+++ b/t/
@@ -524,4 +524,17 @@ test_expect_success 'commit a file whose name is a dash' '
        test_i18ngrep " changed, 5 insertions" output
+test_expect_success '--only works on to-be-born branch' '
+       # This test relies on having something in the index, as it
+       # would not otherwise actually prove much.  So check this.
+       test -n "$(git ls-files)" &&
+       git checkout --orphan orphan &&
+       echo foo >newfile &&
+       git add newfile &&
+       git commit --only newfile -m"--only on unborn branch" &&
+       echo newfile >expected &&
+       git ls-tree -r --name-only HEAD >actual &&
+       test_cmp expected actual

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to