Skip to content

Instantly share code, notes, and snippets.

@mceachen
Last active November 29, 2023 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mceachen/f6632e92e2c84a5409120dec12312505 to your computer and use it in GitHub Desktop.
Save mceachen/f6632e92e2c84a5409120dec12312505 to your computer and use it in GitHub Desktop.
git-restage: Ensure all diffs in currently staged files are staged.
#!/bin/sh
# Stage all diffs found in currently staged files
# This is useful if you've got a set of files ready to commit, but edited one
# or more of them (via prettier, delinting, deleting debug statements, adding
# more tests, ...), and want to make sure those changes are included.
# Usage: `git restage`
# Installation: add this script to your $PATH and chmod +x.
# Hop down to the root of the repository so paths are correct:
cd "$(git rev-parse --show-toplevel)" || exit 1
# For all currently staged files, call `git stage`:
git diff --name-only --cached | xargs --verbose -n 1 -- git stage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment