gunstage
git unstage
as a service
What
There are at least eight ways to unstage files in a Git repository. Remembering which versions of Git support which syntax, under which circumstances, reduced my productivity enough to publish this software in response.
This is a command-line shell plugin for undoing git add
. Too many
staged files? Can’t remember if it’s git reset HEAD
or
git restore --staged --
? Just remember `gunstage`.
If you don’t want to unstage everything, more granular control is available and
gunstage
works exactly as you would expect the opposite of git add
to work.
You can unstage directories or only
specific files: gunstage file1.txt file2.txt directory/
.
Why
There is no git unstage
command. While git restore --staged
often
performs the task, it’s not reliable nor is it an obvious formula based on
Git’s other commands.
Instead of keeping up with the latest incarnation of Git, whose git restore
man
page says the “command is experimental” and “the behavior may change”,
in all capital
letters no less, you can let this script do the remembering for you.
Minutiæ of the pedantic and querulous variety
To unstage content in a Git repository – that is, to undo a
git add
– you must remember which
commands are still in use out of the many I’m aware of having been
recommended so far:
Next, you must be aware of repository context: if the repository is new
and no commit has occurred yet, then git restore --staged
won’t work,
but gunstage
will.
gunstage # 🔫 git unstage as a service
Its name is an abbreviation and portmanteau – or
portmantabbreviation –, of git unstage
arising by analog from
Oh My Zsh’s
other git
aliases.
How
I developed this script in Zsh, for Zsh. But gunstage
ports perfectly to the
Korn shell as well as to Bash. You can literally just change env
’s
argument on
line 1.