Skip to content

Instantly share code, notes, and snippets.

@jmatsu
Last active December 3, 2018 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmatsu/9c8b075bdbe46546b3456ee747e38db7 to your computer and use it in GitHub Desktop.
Save jmatsu/9c8b075bdbe46546b3456ee747e38db7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eu
set -o pipefail
filter_files() {
local -r ref_name="$1"
# select files by TAB
git --no-pager diff --diff-filter=ACMU --name-only "$ref_name" | fzf -m
}
select_ref() {
(git --no-pager branch; git --no-pager branch -r) | awk '$0=$NF' | sort | uniq | fzf
}
main() {
local -r ref_name=$(select_ref)
git checkout "$ref_name" -- $(filter_files "$ref_name" | xargs)
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment