[英]git: hash autocomplete
是否有機會配置git
以在按TAB時自動完成哈希?
請注意,此問題與自動完成無關,但與哈希自動完成有關 。 請參閱我對VonC答案的評論。
您只能通過前幾個字符來引用提交:git將在內部自動完成:
git checkout 9771
因此,您實際上不必輸入完整哈希值!
如果你必須考慮你的倉庫中的所有哈希,這不太可能,因為它不能很好地擴展(如果你有幾百個提交,標簽,...每個都有自己的哈希,這將很快需要很長時間列出它們除非你有一個這個哈希列表的緩存系統)
如果將哈希限制為一個相當新的列表(例如,在當前分支上),可能是,但這不會涵蓋所有用例。
如果選項卡擴展 (在PowerShell中), 這里有一個git shell的例子,在這里進一步增強 。
即使您的環境沒有使用PowerShell,也可以讓您了解“選項卡擴展”的實現。
對不起,我不是bash專家。 但我只是嘗試為csh系列編譯類似的東西,對於那些知道bash的人來說,這應該很容易轉換為bash完成腳本。
我用來獲取有用的命令行,最近的提交哈希類似於:
(git branch | cut -c3-) ; (git branch | cut -c3- | xargs -ibranch git log -n 100 --pretty=format:%+H branch | sort -u)
這行適用於:bash和csh。
基本上它是分支名稱的串聯:
git branch | cut -c3-
和最后一個(n為100)提交名稱(=完整哈希數)
git branch | cut -c3- | xargs -ibranch git log -n 100 --pretty=format:%+H branch | sort -u
csh的完整自動完成語句就像這樣
#
# tcsh completion for Git
#
# Taken from: https://gist.github.com/1663989
# and from: https://gtirtha.wordpress.com/2010/05/14/git-autocomplete/
# extended and merged them into what I (Ingo Schmiegel) like
set _git_commands = (add am cherry-pick commit branch format-patch ls-files help remote merge pull push amend grep rebase reset revert bisect diff difftool blame log checkout fetch stash status wdiff config)
set _git_aliase = `git config --get-regexp 'alias.*' | sed -e 's,alias.,,' | cut -d' ' -f1`
complete git "p/1/($_git_commands $_git_aliase)/" \
"n/help/($_git_commands $_git_aliase)/" \
'n/add/`git status --porcelain|cut -c4-|xargs echo`/' \
'n/br/`git branch|cut -c 3-`/' 'N/br/`git branch|cut -c 3-`/' \
'n/branch/`git branch|cut -c 3-`/' 'N/branch/`git branch|cut -c 3-`/' \
'n/cb/`git branch|cut -c 3-`/' \
'n/cherry-pick/`(git branch|cut -c3-);(git branch|cut -c3-|xargs -ibranch git log -n 100 --pretty=format:%+h branch|sort -u)`/' \
'n/co$/`git branch|cut -c 3-`/' \
'n/config/(--global --get-regexp --list)/' \
'n/diff/(--color-words --name-only)/' \
'n/difftool/(--no-prompt --prompt --tool)/' \
'n/fetch/`git remote`/' \
'n/format-patch/`(echo --output-directory --stdout --signoff);(git branch|cut -c3-);(git branch|cut -c3-|xargs -ibranch git log -n 100 --pretty=format:%+h branch|sort -u)`/' \
'n/log/`git branch|cut -c 3-|xargs echo -- --name-only --name-status --reverse --committer= --no-color --relative --ignore-space-change --ignore-space-at-eol --format=medium --format=full --format=fuller --color --decorate --oneline --summary`/' \
'n/lg/`git branch|cut -c 3-|xargs echo -- --name-only --name-status --reverse --committer= --no-color --relative --ignore-space-change --ignore-space-at-eol --format=medium --format=full --format=fuller --color --decorate --oneline --summary`/' \
'n/ls-files/(--cached --deleted --others --ignored --stage --unmerged --killed --modified --error-unmatch --exclude= --exclude-from= --exclude-standard --exclude-per-directory= --full-name --abbrev)/' \
'n/merge/`git branch|cut -c 3-|xargs echo --no-commit --no-ff --ff-only --squash`/' \
'N/merge/`git branch|cut -c 3-`/' \
'n/pull/(--rebase --no-ff --squash)/' \
'n/push/`git remote`/' 'N/push/`git branch|cut -c 3-`/' \
'n/rebase/`git branch|cut -c 3-| xargs echo --continue --abort --onto --skip --interactive`/' \
'N/rebase/`git branch|cut -c 3-`/' \
'n/remote/(show add rm prune update)/' 'N/remote/`git remote`/' \
'n/reset/(HEAD^)/' \
'N/reset/(HEAD^)/' \
'n/revert/`(echo --edit --no-edit --no-commit --mainline);(git branch|cut -c3-);(git branch|cut -c3-|xargs -ibranch git log -n 100 --pretty=format:%+h branch|sort -u)`/' \
'n/stash/(apply list save pop clear show drop create branch)/' \
請注意,這不會自動檢測哈希的開始,然后可以自動完成它。 csh自動完成基於前一個詞的上下文。 在這個例子中,我只對git命令cherry-pick
, format-patch
和revert
命令使用哈希完成。
在Linux下你有git shell:dev-vcs / git-sh,dev-util / easygit。 此外,如果您為git啟用bash完成,您將獲得自動完成功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.