Git Product home page Git Product logo

gunstage's Introduction

gunstage

🔫 git unstage as a service

GitHub Super-Linter GPLP

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:

  1. git restore --staged (source),

  2. git reset HEAD (source),

  3. git reset (source),

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

  5. git reset HEAD -- (source),

  6. git rm --cached (source),

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

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

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.

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

Requirements

Testing

I tested gunstage atop Zsh 5.8 using Git:

  • 2.17 on Ubuntu 18.04,

  • 2.20 on Debian 9.12,

  • 2.28 on macOS 11.0 and Alpine 3.11 and 3.12, and

  • 2.29 on macOS 11.0 and Alpine 3.11 and 3.12.

From macOS, I use iTerm2; from iOS, I use iSH.

gunstage's People

Contributors

actions-user avatar dependabot[bot] avatar lucaslarson avatar renovate-bot avatar restyled-commits avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.