Git Stage Inverter
A VS Code extension that inverts staged and unstaged Git changes with a graphical panel, per-file selection, and per-hunk conflict resolution when both layers touch the same file.
Built for workflows where a local/standalone environment is kept in the Git index and only feature changes should be committed — without losing the standalone setup and without reset --hard.
The problem it solves
Imagine this workflow:
- You have a standalone environment (scripts, configs, mocks) that must not be committed.
- Before starting a feature, you stage the whole standalone environment. The index becomes the baseline.
- While working, new feature changes appear as unstaged.
- At the end, you want the commit to contain only the feature, with the standalone changes left out again.
Doing this by hand is tedious and risky: git add on everything mixes in the standalone changes, and git reset --hard destroys work. This extension performs the swap in one click, file by file, without changing the content on disk.
How it works
For each selected file:
- staged only → the file is unstaged (
git restore --staged);
- unstaged only (or new/untracked) → the file is staged (
git add);
- both layers → the extension handles it according to the file type:
- tracked text files: a three-way merge between
HEAD, the index (staged), and the worktree (unstaged); hunks that exist on only one side are inverted automatically, and only overlapping hunks go to the resolution screen;
- new files in the index (staged as
A and then modified): a dedicated review of each unstaged change, so you can stage the changes that should go up or remove the whole file from the index — the recommended action for standalone scripts.
In the resolution screen you see the file content and, for each conflicting block, a side-by-side comparison:
- Staged (index) — what was in the stage;
- Unstaged (disk) — what is in the working tree.
For each block you choose:
| Choice |
Effect on the commit |
| Keep and stage |
the whole hunk enters the commit (staged + unstaged) |
| Unstage |
the hunk stays out of the commit (the content remains on disk) |
| Skip |
the hunk remains as it is: staged stays staged, unstaged stays out |
Bulk actions apply the same choice to every block when you want to resolve quickly.
For new files, each change has Stage change / Leave unstaged, and the file also has an Unstage the whole file option. The Unstage new files button removes every new-file entry from the index in one click — ideal for standalone scripts.
Cases where splitting by hunk is not safe automatically fall back to a whole-file decision (the original dialog):
- binary files or files managed by LFS;
- renames/copies;
- a staged deletion with a recreated file;
- mode changes (executable ↔ regular), symlinks, and submodules;
- files that are too large, merge conflicts, or a failed merge calculation.
File content is never modified: the extension only changes the Git index. Everything that was on disk stays on disk, so there is no data loss even if something goes wrong.
Interface
- Activity Bar icon opens the extension interface in the sidebar.
- Lists all changed files, grouped by repository, with the current branch.
- Badges Staged, Unstaged, New, and Partial (when both layers exist).
- Per-file checkbox, with Select all / Clear selection.
- Invert selected (N) button performs the operation in one go.
- Resolve conflicts by hunk screen: file content, highlighted conflicting blocks, side-by-side comparison, and a choice per block.
- Review action on Partial files: opens the hunk resolution directly for that file, without inverting everything.
- New files: review each unstaged change, stage selected changes into the index, or unstage the whole file. The Unstage new files bulk action removes all new-file entries at once.
- Quick actions per file: Stage, Unstage, and diff.
- The same interface is also available as an editor panel through the command palette or the status bar button. The panel is handy when you want more space for complex conflicts.
- Click the file name → full diff (HEAD → disk).
- Click the Staged badge → diff
HEAD → index.
- Click the Unstaged badge → diff
index → disk.
- Automatic refresh when Git state changes (through the built-in Git extension API); it pauses while you are deciding conflicts.
- Progress indicator and a summary of what was done.
Requirements
- VS Code 1.85 or newer.
- Git 2.23 or newer (for
git restore), available on PATH.
- The folder opened in VS Code must be part of a Git repository.
The extension is cross-platform and runs in the workspace extension host, so it also works with Remote-SSH, Dev Containers, and WSL.
Installation
Install from the VS Code Marketplace:
code --install-extension teilorbarcelos.git-stage-inverter
Or build and install locally:
npm install
npm run package
code --install-extension ./git-stage-inverter-0.4.1.vsix
For development, launch an Extension Development Host with:
code --extensionDevelopmentPath="."
Then open the Git Stage Inverter icon in the Activity Bar, run Git Stage Inverter: Open panel from the command palette (Ctrl+Shift+P / Cmd+Shift+P), or use the Stage Inverter button in the status bar.
Development
npm install
npm test # real Git integration tests + extension smoke test
npm run package # builds the .vsix
To debug with F5, open this folder in VS Code and use the Run Extension launch configuration (.vscode/launch.json).
Project structure:
src/
extension.js activation, panel, messages, diffs
git.js Git CLI layer (status, add, restore, blobs, index)
invert.js inversion plan and execution (testable without VS Code)
merge.js three-way merge, conflict blocks, index composition
new-file.js new-file review (diff hunks applied to the index)
panel.js webview HTML (CSP + nonce)
media/
main.js interface logic
style.css styles (VS Code theme)
icon.svg icon used in the panel
icon.png 128×128 icon for the Marketplace
activity-bar.svg monochrome Activity Bar icon
test/
run-tests.js Git integration tests
extension-smoke.js extension test with a mocked VS Code API
Limitations
- Files with merge conflicts are not inverted; resolve the conflict first.
- Per-hunk resolution relies on a textual merge. Binary files, LFS, renames, new files that cannot be reviewed as text, deletions, and mode changes fall back to a whole-file decision.
- The merge uses
git merge-file; custom merge drivers from .gitattributes are not applied.
- Very large files (over 512 KB) are not split by hunk.
- Renames are handled through both paths (old and new), but the diff may appear as “added”.
- For new files, per-change choices decide which unstaged changes enter the commit. The baseline staged content remains in the index unless you choose Unstage the whole file or use Unstage new files.
- The extension does not commit or push: it only organizes the index. Committing is still up to you.
License
MIT.