diff options
| author | Anton Bobov <anton@bobov.name> | 2026-08-26 21:12:45 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2026-08-26 21:12:45 +0500 |
| commit | 4e505b4244fc466cfc88183abfe110d77ccfc3ca (patch) | |
| tree | 205c80ab112cca21449231225b271d8ecd62f53a | |
| parent | 6cc90e320ff6660677708efaeac121fea699c082 (diff) | |
git-keep: add script for merge/rebase conflict resolution
| -rwxr-xr-x | git-keep | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/git-keep b/git-keep new file mode 100755 index 0000000..4f5ab29 --- /dev/null +++ b/git-keep @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# @describe Keep your changes or incoming changes during merge/rebase conflicts +# @meta version 1.0.0 +# @meta require-tools git + +is_rebase() { + [ -d "$(git rev-parse --git-path rebase-merge 2>/dev/null)" ] || [ -d "$(git rev-parse --git-path rebase-apply 2>/dev/null)" ] +} + +do_keep() { + local ours="$1" theirs="$2" + shift 2 + if is_rebase; then + git checkout --"$theirs" "$@" + else + git checkout --"$ours" "$@" + fi + git add "$@" +} + +# @cmd Keep your current branch changes for specified files +mine() { + do_keep "ours" "theirs" "${@:-.}" +} + +# @cmd Keep incoming branch changes for specified files +incoming() { + do_keep "theirs" "ours" "${@:-.}" +} + +eval "$(argc --argc-eval "$0" "$@")" |
