You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create or modify a file that is tracked by Git and has already been committed at least once.
Use a VS Code extension to programmatically attempt a diff between the git: version of the file and the working tree version:
// `target` is a `Change` from the Git API (`indexChanges` or `workingTreeChanges`)constleft=target.originalUri&&target.originalUri.toString()!==target.uri.toString()
? target.originalUri
: target.uri.with({scheme: 'git',query: isStaged ? '^' : '~'});constright=target.uri;vscode.commands.executeCommand('vscode.diff',left,right,title);
Observe that the diff does not open, despite:
The file being modified and committed
The Source Control panel correctly showing a diff
The constructed left URI being well-formed:
git:/Users/.../file.json?^
Expected Behavior
VS Code should open a diff between the git: URI and the file: URI for a staged or modified file, just like the built-in Source Control view.
Actual Behavior
The file does not open in diff view. The command fails silently or falls back to a plain editor. In some cases, target.originalUri is either:
Undefined
Identical to target.uri, resulting in no diff view
Manually constructing git: URIs using .with({ scheme: 'git', query: '^' }) or ?~ fails even for valid files.
Additional Info
We have also tested:
Using Uri.from(...) with authority
Using fully normalized Uri.file(...)
Logging and comparing uri and originalUri
Ensuring the file is in a valid Git state (tracked, staged, or committed)
This appears to be a gap in how vscode.diff resolves manually created git: URIs compared to URIs internally created by the Git extension.
Ask
Can the VS Code team:
Confirm the correct and supported way to programmatically open a diff using vscode.diff for staged or modified files?
Clarify what structure or metadata the Git extension expects in a git: URI to resolve correctly?
Provide a public helper in the Git API to generate valid diffable URIs?
Thank you!
The text was updated successfully, but these errors were encountered:
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.98.2. Please try upgrading to the latest version and checking whether this issue remains.
Does this issue occur when all extensions are disabled?: Yes
Commit: ddc367e
Date: 2025-03-12T13:32:45.399Z (2 wks ago)
Electron: 34.2.0
ElectronBuildId: 11161602
Chromium: 132.0.6834.196
Node.js: 20.18.2
V8: 13.2.152.36-electron.0
OS: Darwin arm64 24.1.0
Steps to Reproduce
git:
version of the file and the working tree version:left
URI being well-formed:Expected Behavior
VS Code should open a diff between the
git:
URI and thefile:
URI for a staged or modified file, just like the built-in Source Control view.Actual Behavior
The file does not open in diff view. The command fails silently or falls back to a plain editor. In some cases,
target.originalUri
is either:target.uri
, resulting in no diff viewManually constructing
git:
URIs using.with({ scheme: 'git', query: '^' })
or?~
fails even for valid files.Additional Info
We have also tested:
Uri.from(...)
with authorityUri.file(...)
uri
andoriginalUri
This appears to be a gap in how
vscode.diff
resolves manually createdgit:
URIs compared to URIs internally created by the Git extension.Ask
Can the VS Code team:
vscode.diff
for staged or modified files?git:
URI to resolve correctly?Thank you!
The text was updated successfully, but these errors were encountered: