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

git-commit: if run with <file> arguments, include files removed through git rm

From
Gerrit Pape <pape@smarden.org>
Date
Sep 4, 2007, 14:43 UTC
Message-ID
<20070904144304.5920.qmail@42e302a26078dc.315fe32.mid.smarden.org>

If git-commit is given a directory as argument to be included in the commit, it uses git ls-files to find out which files to include; this misses files previously removed from the working tree and the index through git rm:

  % git init-db
  Initialized empty Git repository in .git/
  % mkdir bar baz
  % touch bar/file1 baz/file1 baz/file2
  % git add . && git commit -mcommit1
  Created initial commit 1d7dee4: commit1
   0 files changed, 0 insertions(+), 0 deletions(-)
   create mode 100644 bar/file1
   create mode 100644 baz/file1
   create mode 100644 baz/file2
  % git rm baz/file1
  rm 'baz/file1'
  % git commit -- baz/
  # On branch master
  # Changed but not updated:
  #   (use "git add/rm <file>..." to update what will be committed)
  #
  #       deleted:    baz/file1
  #
  no changes added to commit (use "git add" and/or "git commit -a")
This patch lets it additionally use git ls-tree to look for the files in
the HEAD tree, but I guess there's a smarter way to fix this.
---
 git-commit.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 1d04f1f..3ac7c4f 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -381,6 +381,7 @@ t,)
 		fi
 		TMP_INDEX="$GIT_DIR/tmp-index$$"
 		commit_only=`git ls-files --error-unmatch -- "$@"` || exit
+		commit_only="$commit_only "`git ls-tree -r --name-only HEAD -- "$@"` || exit
 
 		# Build a temporary index and update the real index
 		# the same way.
-- 
1.5.3
Next: Junio C Hamano
Message 1 of 3 in “git-commit: if run with <file> arguments, include files removed through git rm”
  1. Gerrit PapeSep 4, 2007
  2. Junio C HamanoSep 4, 2007
  3. Gerrit PapeSep 5, 2007

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.