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

Re: selective git-update-index per diff(1) chunks

From
Linus Torvalds <torvalds@osdl.org>
Date
Dec 1, 2006, 16:06 UTC
Message-ID
<Pine.LNX.4.64.0612010740160.3695@woody.osdl.org>
In-Reply-To
<b6fcc0a0612010323x7554e47m5e6bdafe85fc8224@mail.gmail.com>
On Fri, 1 Dec 2006, Alexey Dobriyan wrote:
Show 6 quoted lines
> 
> Has anyone thought about aggregating this into git-update-index or
> somewhere?
> 
>    git-update-index -C1,3    #chunks 1, 3
>    git commit
You can already do it, but it's called something else.

Instead of updating a certain hunk (which is fundamentally wrong, since it depends on "diff" even working on that file), you can tell git-update-index to update a certain _state_ for an arbitrary number of files. Namely:

	git-update-index [--cacheinfo <mode> <object> <file>]*

However, that obviously is very much a _plumbing_ command, and you need to have some higher-level GUI on top of it to actually pick out the chunks (if that is what you want) and generate the object(s) associated with the file(s) with only those chunks and then do the above "install this state into the index/staging area/whatever".

In other words, git already supports this on a _technical_ level, but does not have the high-level interfaces for it, and quite frankly "git-update-index" _shouldn't_ have the high-level interfaces for it. It's designed to be the low-level technology, not the actual interface.

I think it's more appropriate for a GUI front-end, frankly, but you could script it fairly easily with whatever your favourite patch editing tool:

 (a) Generate the "result" file you want in /tmp or something, using patch 
     editing tools to extract a partial patch and apply it to the original 
     file.
 (b) Use "git-hash-object" to create the backing store object, and get the 
     SHA1 for that file.
 (c) Use "git-update-index --cacheinfo <mode> <sha1> <filename>" to 
     populate that new entry of yours into the index.
 (d) Do (a)-(c) as many times as you like to handle all the files you 
     want to commit, and then just call "git commit"

iow, it's not hard, but no, git on its own is _not_ a patch-based system, and doesn't do things hunk-for-hunk. You need that "hunk selector" interface on top of it.

Previous: Sam VilainNext: Sven Verdoolaege
Message 7 of 12 in “selective git-update-index per diff(1) chunks”
  1. Alexey DobriyanDec 1, 2006
  2. Peter BaumannDec 1, 2006
  3. Junio C HamanoDec 1, 2006
  4. Anand KumriaDec 1, 2006
  5. Johannes SchindelinDec 1, 2006
  6. Sam VilainDec 2, 2006
  7. Linus TorvaldsDec 1, 2006
  8. Sven VerdoolaegeDec 4, 2006
  9. Jakub NarebskiDec 4, 2006
  10. Jakub NarebskiDec 4, 2006
  11. Sven VerdoolaegeDec 4, 2006
  12. Jakub NarebskiDec 4, 2006

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.