Skip to content

Instantly share code, notes, and snippets.

@jfairbank
Last active August 29, 2015 14:26

Revisions

  1. jfairbank revised this gist Jul 29, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git-diff-add.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/bin/bash
    # git diff a file and then be presented with the option to stage the file with "y" or stage a portion with patch via "p"
    # git diff a file and then be presented with the option to stage
    # the file with "y" or stage a portion with patch via "p"

    filepath="${1-.}"

  2. jfairbank created this gist Jul 29, 2015.
    17 changes: 17 additions & 0 deletions git-diff-add.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash
    # git diff a file and then be presented with the option to stage the file with "y" or stage a portion with patch via "p"

    filepath="${1-.}"

    git diff "$filepath"

    [[ $? -ne 0 ]] && exit

    printf "\nOk to stage? [y/p/N]: "
    read stage

    if [[ "$stage" == "y" || "$stage" == "Y" ]]; then
    git add "$filepath"
    elif [[ "$stage" == "p" || "$stage" == "P" ]]; then
    git add -p "$filepath"
    fi