Git: Rework patch commands.

This commit is contained in:
Dmitry Voronin 2024-11-24 04:24:07 +03:00
parent 25f0252908
commit 76f33841c8
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k

View file

@ -123,22 +123,34 @@
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
} }
# Git patch create. # Git patch from staged diff.
# Usage: gpc > <FILE> # Usage: gpd
function gpc() { function gpd() {
git diff --staged --patch --binary git diff --staged --patch --binary --minimal
} }
# Git patch (apply). # Git patch from commit.
# Usage: gp <FILE> # Usage: gpc [REF] [COUNT]
function gp() { 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 <FILE>
function gpa() {
git apply --index "''${@}" git apply --index "''${@}"
} }
# Unstage changes. # Unstage changes.
# Usage: grs <FILES> # Usage: grs [FILES]
function grs() { function grs() {
git restore --staged "''${@}" local target=''${@}
[[ "''${target}" = "" ]] && target="."
git restore --staged "''${target}"
} }
# Run git garbage collection. # Run git garbage collection.
@ -155,10 +167,7 @@
# Usage: ga [FILES] # Usage: ga [FILES]
function ga() { function ga() {
local target=''${@} local target=''${@}
[[ "''${target}" = "" ]] && target="."
if [[ "''${target}" = "" ]]; then
target="."
fi
git diff ''${target} git diff ''${target}
git add ''${target} git add ''${target}