revert-staged.py
revert-staged.py reverts both staged AND unstaged changes for a file back to the last committed version (HEAD).
What It Does
The script:
- Verifies the file is tracked by git
- Warns the user about discarding changes
- Runs
git restore --source=HEAD <file>to revert the file
Usage
python3 scripts/revert-staged.py <file_path>
Example
python3 scripts/revert-staged.py juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
⚠️ Warning
This will discard ALL changes (both staged and unstaged) for the specified file, reverting it back to the last commit.
Exit Codes
0- Success1- Error (file not tracked, git command failed, etc.)
Requirements
- Python 3.6 or higher
- Git (git command must be in PATH)
- No external Python dependencies (uses only standard library)
Notes
- The file must be tracked by git (the script verifies this)
- This is a destructive operation - changes cannot be recovered
- Use
revert-unstaged.pyif you only want to revert unstaged changes while preserving staged changes
Share feedback or follow-up questions for this page directly through GitHub.