我发现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