git/list[1] front-page[2] threads[3] people[4] search[5] about
 

unexpected empty commit after checkout with uncommitted index

From
Chris Johnsen <chris_johnsen@pobox.com>
Date
Jul 3, 2009, 11:28 UTC
Message-ID
<B98E6930-01E8-4A14-9C09-CC2BACC3389C@pobox.com>

The following test script fails after 83ae209 (checkout branch: prime cache-tree fully, 2009-04-20).

-- 
Chris

#!/usr/bin/env dash
abort() {
     printf "$@"
     exit 128
}
failed=0
fail() {
     failed=1
     printf "$@"
}

set -e

GIT="${1:-git}"
case "$GIT" in
./*|../*) GIT="$PWD/$GIT"
esac
type "$GIT" > /dev/null ||
     abort 'bad git command?: %s\n' "$GIT"

tn=checkout-with-changed-index
td="$(mktemp -d -t "$tn")"
if test -z "$td"; then
     td="/tmp/$tn"
     mkdir "$td" ||
         abort 'unable to create test dir: %s\n' "$td"
     test -d "$td"/.git &&
         abort '.git already exists in test dir: %s\n' "$td"
fi
trap 'rm -rf "$td"' 0

cd "$td"
"$GIT" --version
"$GIT" init
echo foo > foo
echo bar > bar
"$GIT" add foo bar
"$GIT" commit -m 'add foo, bar'
echo BAR > bar
echo baz > baz
"$GIT" rm foo
"$GIT" add bar baz
"$GIT" checkout -b new
"$GIT" commit -m 'rm foo, change bar, add baz'

# After 83ae209 the commit on "new" (or even a detached HEAD if
# we use "HEAD@{0}" instead of "-b new") appears to be an empty
# commit. The same thing happens whether the changes (add new, rm
# existing, add edited) are done in a group, as above, or
# individually.  Both before and after the commit, [git status]
# seems to show that the changes are properly staged, but they
# never make it into the committed tree. [git reset] and then
# [git add --all] resolves the strange state and allows the
# expected commit to take place.

test -z "$("$GIT" ls-tree HEAD foo)" ||
     fail '*** foo was not removed\n'
test "$("$GIT" cat-file blob HEAD:bar)" = "BAR" ||
     fail '*** bar was not changed\n'
test "$("$GIT" cat-file blob HEAD:baz)" = "baz" ||
     fail '*** baz was not added\n'
exit $failed
Message 1 of 1 in “unexpected empty commit after checkout with uncommitted index”
  1. Chris JohnsenJul 3, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.