2012-10-29 27 views
1

當我在Windows中打開git bash時,如何打印包含我的git別名的歡迎消息?在Windows 7的git bash中打印歡迎信息

+0

哪個命令,你會手動運行,讓你想看到的輸出? –

+0

我不知道,我可能必須手動執行此操作,比如'echo「可用的別名:au:add -u,ct = commit ...' – chwi

+0

哪個_git_命令可以手動運行? –

回答

4

在交互式登錄到Bash shell(bash --login)後,終端上會顯示/etc/motd的內容。如果版本爲Git for Windows你已經省略了文件/etc/motd,用cat或你最喜歡的編輯器創建一個。

# == Git Bash on Windows == 
# - /etc/motd = Message of the Day 
# - - - - - - - - - - - - -  
cat > /etc/motd 
Welcome to the Git Bash Shell 
- Try "pwd -W" versus "pwd -L" 
- - - - - - - - - 

CTRL-d

3

只需定義一個HOME環境變量(未在msysgit中包含的git-bash.bat腳本中定義)。

在你選擇(例如:%USERPROFILE%)的目錄,定義一個.bashrc文件,包含以下內容:

git config --get-regexp alias 

(從 「How to list/show Git aliases?」)

,將顯示所有每次你用msysgit打開一個bash會話時,git別名。

alias.st status 
alias.lg log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relati ve 
alias.co checkout 
alias.ci commit 
alias.br branch 
alias.lo !sh -c 'git log $1' - 
alias.impact !git ls-files -z | xargs -0n1 git blame -w -C | sed -r 's/^[^(]+\((.*) [0-9]{4}-.*/\1/' | sed -r 's/ +$//' | sort -f | uniq -c | sort -nr 

然而,OP Wilhelmsenin the comments

你知道我怎麼可以省略對打印字別名嗎?

當然,這是一個基本bash String manipulation操作:

a=$(git config --get-regexp alias) 
echo "${a//alias./}" 

,將顯示:

st status 
lg log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative 
co checkout 
ci commit 
br branch 
lo !sh -c 'git log $1' - 
impact !git ls-files -z | xargs -0n1 git blame -w -C | sed -r 's/^[^(]+\((.*) [0-9]{4}-.*/\1/' | sed -r 's/ +$//' | sort -f | uniq -c | sort -nr 

注意${a//alias./}以取代所有 'alias.' 從字符串「 a'由一個空字符串。
並且echo "$..."的雙引號是強制性的以保持換行符。 (否則,所有別名將顯示在一行行)。

+0

謝謝,這工作完美! – chwi

+0

@Wilhelmsen http:// support。 microsoft.com/kb/310519或http://www.itechtalk.com/thread3595.html(好吧,我沒有看到你最後的編輯到你的評論) – VonC

+0

你知道我怎麼可以省略單詞'別名'on打印? – chwi