> On May 1, 2025, at 9:31 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote: > > "Kristoffer Haugsbakk" <kristofferhaugsbakk@xxxxxxxxxxxx> writes: > >>> Johannes Altmanninger submitted patch v3 titled "apply: --intent-to-add >>> should imply --index" to fix this issue. >>> >>> Is this fix merged? If so, which Git version includes this fix. >> >> I can’t find any commits by Johannes Altmanninger that addresses this. >> I also can’t find any commits that start with `apply: --intent-to-add`. > > The documentation says this: > > --intent-to-add:: > When applying the patch only to the working tree, mark new > files to be added to the index later (see `--intent-to-add` > option in linkgit:git-add[1]). This option is ignored unless > running in a Git repository and `--index` is not specified. > Note that `--index` could be implied by other options such > as `--cached` or `--3way`. > > It is clear that whoever wrote it understands that for this option > to be effective, the patch needs to affect the index, and one way to > do so is for the user to pass `--index`. But at the same time, that > is not the only option that makes the command touch the index (e.g., > `--cached` does, too), and it would make it behave incorrectly if a > patch automatically pretends that `--index` was given when this > option was given. The person that wrote that understood that there’s a conflict between —index and —intent-to-add: —index means add new files to the index and stage them for commit —intent-to-add means add an entry for the file to the index but don’t stage it; ie it will be added later The author of this commit decided that if —intent-to-add and —index are both specified, then —index takes precedence. > > I can't find the patch either, but given the above documentation, is The reason you can’t find the patch is because you took issue with the fix provided by Johannes and asked for more analysis. If you want I can dig up the details of that thread. > it even still relevant? > This issue is still very relevant. Firstly, let me point out the major issue with the current functionality: Given a repo with one file, “b.c” and the following diff that adds file “a.c": ryan@Ryans-Macbook-Pro git-repo % cat diff diff --git a/a.c b/a.c new file mode 100644 index 0000000..e69de29 Here’s what happens when you run git apply —intent-to-add: ryan@Ryans-Macbook-Pro git-repo % git apply --intent-to-add diff ryan@Ryans-Macbook-Pro git-repo % git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: b.c Bam! b.c gets marked for deletion. The whole index gets replaced with just the files that are marked by —intent-to-add. That’s very bad. Lastly, I’d like to point out my use case for —intent-to-add. In many VCSs if you run ‘apply’, ‘diff’, and ‘commit’ in sequence and in a clean workspace with no changes, the diff that gets fed to ‘apply’ should look the same as the diff that you get from running ‘diff’, which should be the same as the diff created by the commit command. Because of the index, that doesn’t happen with Git. When applying a patch in git, new files get added to the worktree but they are not registered in the index. Thus git diff never sees them. Additionally, those files will be missed by commit even if you use -a. The —intent-to-add switch fixes this workflow and allows files to remain out of the index until the user is ready for them. Thanks > Thanks.