Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🔫  `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

NotificationsYou must be signed in to change notification settings

LucasLarson/gunstage

Repository files navigation

🔫git unstage as a service

🕶 Mentioned in AwesomeGitHub Super-LinterGPLPdoi:10.5281/zenodo.6581323

What

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.

Why

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 restorecauses 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.

Minutiæ of the pedantic and querulous variety

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:

  1. git restore --staged (source),

  2. git reset HEAD (source),

  3. git reset -q HEAD -- (source (via))

  4. git reset (source),

  5. git restore --staged -- (source),

  6. git reset HEAD -- (source),

  7. git rm --cached (source),

  8. git reset -- (source), and even

  9. git rm --cached -- # ffs (source).

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.

Enter
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.

How

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.

Installation

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'

Requirements

Testing

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

From macOS, I useiTerm2; from iOS, Iuse iSH.

Credit

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp