2017-01-01 86 views
0

這裏是我的git push wordpress目錄的功能。如何在別名中設置函數參數?

pushwp(){ 
cd /var/www/html/wp 
git init 
git add * 
git commit -am "$1" 
git push -f origin master 
} 

pushwp函數處於良好狀態。

pushwp "it is a test" 
Reinitialized existing Git repository in /var/www/html/wp/.git/ 
On branch master 
nothing to commit, working directory clean 
Everything up-to-date 

現在分配帶有別名的函數。

alias pushme='pushwp(){ 
cd /var/www/html/wp 
git init 
git add * 
git commit -am "$1" 
git push -f origin master 
}' 

讓我們試試吧。

pushme "it is a test" 
bash: syntax error near unexpected token `"it is a test"' 

如何解決別名?

+0

你已經有一個_function,_爲什麼地球上,你會包裝在一個別名?這個不成立!只需使用該功能。除非你想要一個_git alias._ –

+0

你不需要。別名不是功能。 – melpomene

+0

你的別名只*定義*的功能;它不會這麼稱呼它。你可以讓別名定義*和*調用函數('alias pushme ='pushwp(){...}; pushwp''),但是正如@gniourf_gniourf指出的那樣,很少或根本沒有理由這麼做。 – chepner

回答

0

正如評論,你需要定義和調用你的別名。但你不需要在這裏。

確保每次要推送時都不要初始化repo:git init應該只執行一次,而不是該別名的一部分。

你也可以使用git add .代替git add *(其依靠的bash擴展)

相關問題