我製成的殼的別名,我打算在一起使用與其他命令:使用git殼別名
this = "!f() { git rev-parse --abbrev-ref HEAD; }; f"
的想法是,它會輸出電流的git分支我在,和使用它像這樣:
git push -u origin this
當我只需運行別名它正確輸出的電流分支,但是當我嘗試使用它像上面的例子中它給了我一個錯誤:
error: src refspec this does not match any.
error: failed to push some refs to 'myrepo.git'
如果我嘗試使用相同的命令,但實際上是在編寫分支名稱(git push -u origin <branch>
),它可以正常工作。
我在做什麼錯?當我將它與另一個命令結合使用時,它不能展開我的this
別名嗎?
git不會在命令行隨機點擴展別名(這將需要大量掃描並始終工作)。你可以得到最接近的是'git push -u origin「$(git this)」'但我不知道我看到這個別名的使用(並且它不需要封裝函數)。 – 2014-12-05 11:07:39
我們使用長分支名稱,有時100多個字符。將'this'映射到當前分支名稱會很好,這樣您就不必輸入分支名稱。函數環繞僅僅是因爲我對此很陌生...... – user1021726 2014-12-05 11:09:49
通過將別名映射到shell自己的別名,可以使它更短,如:'git push -u origin $(this)'...這不是完美的解決方案,但它相當短 – user1021726 2014-12-05 11:49:52