我發現git examples with fzf(fuzzy finder)他們確實很好。 像:如何用模糊查找器獲取git的分支?
# fbr - checkout git branch
fbr() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# fbr - checkout git branch (including remote branches)
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $((2 + $(wc -l <<< "$branches"))) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
我有這個在我的的.bashrc
bind '"\C-b": "fbr \n"'
後,我按按Ctrl-B我能選擇一個git的分支並切換之後我按回車,但有沒有辦法鍵入東西,如git push staging
(然後獲取分支列表,並將選定的分支右移到分支列表前的光標所在位置,然後按Enter鍵將所選分支推送到staging
)
例: git push staging
(按Ctrl-B - 選擇一個分支),我希望得到這個輸出 - git push staging selected_branch
考慮git完成? https://github.com/git/git/blob/master/contrib/completion/git-completion.bash – webb
@webb非常感謝你。 – whitesiroi