diff --git a/home/program/bash/module/Git.nix b/home/program/bash/module/Git.nix index 6226772f..b6b2de81 100644 --- a/home/program/bash/module/Git.nix +++ b/home/program/bash/module/Git.nix @@ -123,22 +123,34 @@ git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached } - # Git patch create. - # Usage: gpc > - function gpc() { - git diff --staged --patch --binary + # Git patch from staged diff. + # Usage: gpd + function gpd() { + git diff --staged --patch --binary --minimal } - # Git patch (apply). - # Usage: gp - function gp() { + # Git patch from commit. + # Usage: gpc [REF] [COUNT] + function gpc() { + local ref="''${1}" + local count="''${2}" + [[ "''${ref}" = "" ]] && ref="HEAD" + [[ "''${count}" = "" ]] && count=1 + git format-patch --stdout --minimal --patch --binary -''${count} "''${ref}" + } + + # Git patch apply. + # Usage: gpa + function gpa() { git apply --index "''${@}" } # Unstage changes. - # Usage: grs + # Usage: grs [FILES] function grs() { - git restore --staged "''${@}" + local target=''${@} + [[ "''${target}" = "" ]] && target="." + git restore --staged "''${target}" } # Run git garbage collection. @@ -155,10 +167,7 @@ # Usage: ga [FILES] function ga() { local target=''${@} - - if [[ "''${target}" = "" ]]; then - target="." - fi + [[ "''${target}" = "" ]] && target="." git diff ''${target} git add ''${target}