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

Re: git apply --intent-to-add deletes other files from the index

From
Johannes Altmanninger <aclopte@gmail.com>
Date
Oct 30, 2021, 20:39 UTC
Message-ID
<20211030203916.zopggbajumvb4z3f@gmail.com>
In-Reply-To
<0DB10E05-094D-4382-AD1F-657878B06A80@cisco.com>
On Tue, Oct 26, 2021 at 03:11:36PM +0000, Ryan Hodges (rhodges) wrote:
Show 24 quoted lines
> Hi all,
>  
> I’ve got a quick question about ‘git apply –intent-to-add’.  If I’ve got a patch that just adds one file to the tree:
>  
> [sjc-ads-2565:t.git]$ git diff
> diff --git a/c.c b/c.c
> new file mode 100644
> index 0000000..9daeafb
> --- /dev/null
> +++ b/c.c
> @@ -0,0 +1 @@
> +test
>  
> and I apply that patch with –intent-to-add:
>  
> [sjc-ads-2565:t.git]$ git apply --intent-to-add c.diff
>  
> The newly added file is tracked but other files in the tree get marked as deleted:
>  
> [sjc-ads-2565:t.git]$ git status
> On branch master
> Changes to be committed:
>   (use “git restore –staged <file>…” to unstage)
>                 deleted:    a.c

Yep, looks like a bug to me. git apply should never change the status of files that are not mentioned in the input patch.

Show 8 quoted lines
>                 deleted:    b.c
>  
> Changes not staged for commit:
>   (use “git add <file>…” to update what will be committed)
>   (use “git restore <file>…” to discard changes in working directory)
>                 new file:   c.c
>  
> It looks like Git created a new index with only the newly added file in the patch.
Seems so.
> However, I’d like Git to just add one entry to the index corresponding
> to the newly added file in the patch.  Is this a bug or am I completely
> misinterpreting the goal of ‘intent-to-add’.
Yeah, I think your "git apply --intent-to-add c.diff" should behave exactly like
	echo test > c.c && git add --intent-to-add c.c
Previous: Ryan Hodges (rhodges)Next: Ryan Hodges
Message 2 of 12 in “git apply --indent-to-add deletes other files from the index”
  1. Ryan Hodges (rhodges)Oct 26, 2021
  2. Johannes AltmanningerOct 30, 2021
  3. Ryan HodgesOct 30, 2021
  4. Johannes AltmanningerOct 31, 2021
  5. apply: make --intent-to-add not stomp indexJohannes Altmanninger, Oct 30, 2021
  6. apply: make --intent-to-add not stomp indexJohannes Altmanninger, Oct 30, 2021
  7. Junio C HamanoNov 1, 2021
  8. Re* [PATCH v2] apply: make --intent-to-add not stomp indexJunio C Hamano, Nov 1, 2021
  9. Johannes AltmanningerNov 6, 2021
  10. apply: --intent-to-add should imply --indexJohannes Altmanninger, Nov 6, 2021
  11. Johannes AltmanningerNov 6, 2021
  12. Johannes AltmanningerNov 6, 2021

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.