- Notifications
You must be signed in to change notification settings - Fork3
🔫 `git unstage` as a service: a Git plugin for the shell that automagically remembers all the different commands there are to remove files from staging and when to use each
License
LucasLarson/gunstage
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
🔫git unstage
as a service
There are at least nine ways to unstage files in a Git repository.Remembering which versions of Git support which syntax, under whichcircumstances, reduced my productivity enough to publish this softwarein response.
This is a command-line shell plugin for undoinggit add
. Too manystaged files? Can’t remember if it’sgit reset HEAD
orgit restore --staged --
? Just remembergunstage
orgit unstage
.
gunstage
works exactly as you would expect it to as it performs the oppositeofgit add
. You can unstage directories and specific files in as fewcommands as you’d like:gunstage file1.txt file2.txt directory/
.
Want to unstage everything? Well that’s as easy asgunstage --all
orgunstage -A
.
There is nogit unstage
command packaged as part of Git’sdefault tooling. Whilegit restore --staged
often performs the task,it’s not an obvious formula based on Git’s other commands.git restore --staged
is also unreliable, havingenteredGit’s vocabulary in 2019, after some 14 years of releaseswithout it. Many older releases remain in the wild andgit restore
causes them to fail and choke. This software gracefully and silently accountsfor those situations by always sending the syntax that Git used from 2005 until2019:git reset
.
Instead of keeping up with the latest incarnation of Git, whose manual saysgit restore
“IS EXPERIMENTAL” and “THE BEHAVIOR MAY CHANGE” (emphasisin original), youcan let this script do the remembering for you.
To unstage content in a Git repository – that is, to undo agit add
– you must rememberwhichcommands are still in use out of the many I’m aware of having beenrecommended so far:
Next, you must be aware of repository context: if the repository is newand no commit has occurred yet, thengit restore --staged
won’t work,butgunstage
will.
gunstage# 🔫 git unstage as a servicegit unstage# 🔫 it just works!
Its name is an abbreviation and portmanteau ofgit unstage
arising byanalog fromOh My Zsh’sother Git aliases.
The scripts are written in Bourne shell-flavored, KornShell- and Zsh-compatibleBash, which is masquerading as Z shell with a.zsh
filename extension soOh My Zsh recognizes it as a plugin. What does that mean? Thesyntax isaslow-tech as possible while performing sophisticated work to do one thing anddo it well:git unstage
.
gunstage
can beinstalled as aplugin,installedusing Fig, or you can just clone this repository, run the followingcommand, and then restart your terminal:
$printf'%s\n''. /path/to/gunstage.plugin.zsh' \>>"${HOME%/}"'/.'"${SHELL##*[-./]}"'rc'
I testedgunstage
atop Zsh 5.8 and Bash 3.2 using Git:
2.17 on Ubuntu 18.04,
2.20 on Debian 9.12,
2.28, 2.29, and 2.30 on macOS 11.0 and Alpine 3.11 and 3.12,and
This repository’spreviewimage was created byTwitterin 2018.
About
🔫 `git unstage` as a service: a Git plugin for the shell that automagically remembers all the different commands there are to remove files from staging and when to use each