git基礎:《Git 別名》學習筆記
阿新 • • 發佈:2019-01-25
log 別名 fig signed 是你 ranch 不要猶豫 自動 想要
在我們結束本章 Git 基礎之前,正好有一個小技巧可以使你的 Git 體驗更簡單、容易、熟悉:別名。 我們不會在之後的章節中引用到或假定你使用過它們,但是你大概應該知道如何使用它們。
Git 並不會在你輸入部分命令時自動推斷出你想要的命令。 如果不想每次都輸入完整的 Git 命令,可以通過 git config 文件來輕松地為每一個命令設置一個別名。 這裏有一些例子你可以試試:
$ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status
這意味著,當要輸入 git commit 時,只需要輸入 git ci。 隨著你繼續不斷地使用 Git,可能也會經常使用其他命令,所以創建別名時不要猶豫。
在創建你認為應該存在的命令時這個技術會很有用。 例如,為了解決取消暫存文件的易用性問題,可以向 Git 中添加你自己的取消暫存別名:
$ git config --global alias.unstage 'reset HEAD --'
這會使下面的兩個命令等價:
$ git unstage fileA
$ git reset HEAD -- fileA
這樣看起來更清楚一些。 通常也會添加一個 last 命令,像這樣:
$ git config --global alias.last 'log -1 HEAD'
這樣,可以輕松地看到最後一次提交:
$ git last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel <[email protected]>
Date: Tue Aug 26 19:48:51 2008 +0800
test for current head
Signed-off-by: Scott Chacon <[email protected]>
git基礎:《Git 別名》學習筆記