Skip to content

git: Fix stage/unstage failure with a large number of files#47800

Merged
cole-miller merged 3 commits intozed-industries:mainfrom
marcocondrache:git-pipes
Jan 31, 2026
Merged

git: Fix stage/unstage failure with a large number of files#47800
cole-miller merged 3 commits intozed-industries:mainfrom
marcocondrache:git-pipes

Conversation

@marcocondrache
Copy link
Contributor

@marcocondrache marcocondrache commented Jan 27, 2026

Git commands can fail when staging or unstaging a very large number of files because each file path is passed as a separate CLI argument. Once the argument list grows beyond the OS limit, git errors with Argument list too long (os error 7).

Since git 2.26, pathspecs can be read from stdin, which lets us avoid passing thousands of paths as arguments and bypass this limitation.

I looked for existing issues related to this but couldn’t find any.

Repro:

  • Clone rust-lang repo
  • Delete root tests folder
  • Try to stage or unstage (40,000+ files)
  • Git fails with Argument list too long (os error 7)

Release Notes:

  • Fixed an issue where stage/unstage could fail when operating on a very large number of files

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 27, 2026
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Jan 27, 2026
@cole-miller
Copy link
Member

Thank you and nice find!

My only worry with this is that we'll lose support for people with older git binaries on their system. Maybe we could use pathspec-from-file only if it's available, and fall back to making multiple calls to the git binary? (Admittedly the latter isn't great but it's better than just failing.)

@marcocondrache
Copy link
Contributor Author

@cole-miller thanks! I added the fallback to the old command. Since pathspec-from-file is available from git 2.26 (2020), most users should hit the first path anyway. The stage method uses update-index, which has supported --stdin since the earliest releases, so this should be safe.

@cole-miller
Copy link
Member

Thanks!

@cole-miller cole-miller enabled auto-merge (squash) January 31, 2026 21:46
@cole-miller cole-miller merged commit 839b4f1 into zed-industries:main Jan 31, 2026
27 checks passed
cole-miller added a commit that referenced this pull request Feb 3, 2026
cole-miller added a commit that referenced this pull request Feb 3, 2026
…47800)" (#48238)

This reverts commit 839b4f1.

This changed caused a regression on Windows (reproducer: have a repo
with some unstaged changes to tracked files, and click `Commit
Tracked`).

cc @marcocondrache 

Release Notes:

- N/A (nightly only)
adb-sh pushed a commit to adb-sh/zed that referenced this pull request Feb 5, 2026
…ed-industries#47800)" (zed-industries#48238)

This reverts commit 839b4f1.

This changed caused a regression on Windows (reproducer: have a repo
with some unstaged changes to tracked files, and click `Commit
Tracked`).

cc @marcocondrache 

Release Notes:

- N/A (nightly only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants