Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (87 sloc) 3.29 KB
layout author title date desc img categories tags extras interesting toc
post
Wouter Van Schandevijl
Git-NumberedAdd for PowerShell
2018-08-30 08:00:00 -0700
Tired of copying <code>git status</code> output for <code>git add</code> input for the millionth time? Despair no more for <code>Git-NumberedAdd</code> is here!
git-add-numbered-add.jpg
productivity
git
powershell
githubproject githubtext
Git-NumberedStatus, Add, Diff and Reset ps1 source
desc git
Similar implementation in Bash
scmbreeze/scm_breeze
desc git
Similar implementation in Perl
holygeek/git-number
title icon
Numbered Add
icon-git

After copying file paths from git status output and pasting them after a git add quite a few times by now, I've written a small PowerShell script to stage the files by index.

Git-NumberedStatus (alias: gs)

Displays the output of git status --short together with fabricated indexes like so

Git-NumberedStatus{: .img-responsive}

Working directory color codes:

  • Yellow: Modified (file0 to file3)
  • DarkMagenta: Deleted (file4)
  • Blue: Added (file5)

Git-NumberedStatus accepts extra CLI arguments. Example: `gs -u` to see all `--untracked-files`. Configure the color output by modifying `$global:gitStatusNumbers`.

With Numstat

If $global:gitStatusNumbers.includeNumstat is true, Git-NumberedStatus will also execute a git diff --numstat and add lines added/deleted to the output.

Git-NumberedStatus with --numstat{: .img-responsive}

Git-NumberedAdd (alias: ga)

All set to stage some files!

PS> Git-NumberedAdd 0 1 2
add 'file0'
add 'file1'
add 'file2'

The same can be achieved with:

  • Git-NumberedAdd 0-2
  • Git-NumberedAdd -3
  • Git-NumberedAdd 012 (but only if there is a max of 10 files in the git status)

`Git-NumberedAdd +3` would add file4 and file5 in the above scenario.

Git-NumberedDiff (alias: gd)

Works like Git-NumberedAdd but can also be called without arguments to see the diff of all files. It will call git add -N for all newly created files so that they also show up in the diff.

git diff --cached is currently not implemented in this script.

Git-NumberedReset (alias: grs)

This only works for files already staged. Example output:

Git-NumberedStatus{: .img-responsive}

To, for example unstage file0 and file4

PS> Git-NumberedReset 02
Unstaged changes after reset:
M       file0
M       file1
M       file2
D       file4

Other functions

Git-GetFileNameByIndex 2

Alternatives

Sometime similar is actually built into Git itself

git add --interactive # or -i for short

Once in interactive mode:

git add --interactive{: .img-responsive}

And then use 2: Update to stage files.


Also, see below for similar implementations in Bash and Perl.