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

Re: Any way to edit the file in index directly?

From
Jeff King <peff@peff.net>
Date
Apr 8, 2009, 02:10 UTC
Message-ID
<20090408021041.GB18244@coredump.intra.peff.net>
In-Reply-To
<46dff0320904071803k68fddff4j226760392e0c5bcc@mail.gmail.com>
On Wed, Apr 08, 2009 at 09:03:03AM +0800, Ping Yin wrote:
> There seems to be a patch for this ( add -e?), but i forget where to
> find it.

"add -p" has an "e"dit option for editing the patch. I don't recall any way of directly editing the content.

> For a big change, instead of "add -p", it may be easier to edit the
> index directly ( with the corresponding worktree file alongside)

I'm not sure what you mean by "alongside". If you mean "by editing a temporary file that corresponds to the index file without munging your worktree file", then you can do:

  FILE=foo.c
  git show :$FILE >$FILE.tmp
  $EDITOR $FILE.tmp
  object=`git hash-object -w $FILE.tmp`
  git update-index --cacheinfo 100644 $object $FILE

And obviously you could make a script for that if you wanted (but at the very least, you would need quotes to handle files with spaces, and probably some magic to handle smudge/clean filters and CRLF properly for the tempfile).

-Peff
Previous: Ping YinNext: Jeff King
Message 2 of 7 in “Any way to edit the file in index directly?”
  1. Ping YinApr 8, 2009
  2. Jeff KingApr 8, 2009
  3. Jeff KingApr 8, 2009
  4. Ping YinApr 8, 2009
  5. Markus HeidelbergApr 8, 2009
  6. Johannes SchindelinApr 8, 2009
  7. Ping YinApr 8, 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.