全文共1667字,預計學習時長5分鐘
1. 以「; 」(分號)分隔的多個git命令
以分號分隔可使用多個Git命令:
$ git --version; git branch // separated by semi-colon
2.git別名命令
命令別名能提高可重用性。
將gitremote -v(用於檢查遠程源的命令)別名為show-origin:
$ git config --global alias.show-origin 'remote -v'
$ git show-origin
將git log --graph--pretty=oneline (列印提交日誌的命令)別名為show-graph:
3.名為『 .git』的隱藏文件夾
隱藏的.git文件夾包含提交、分支和文件的歷史記錄。因此,需要複製.git 文件夾並複製整個應用程式及git歷史記錄(提交歷史等)。要複製隱藏的文件夾,需要運行-r 選項:
$ cp -r <originalFolder><destinationFolder>
要查看隱藏的文件夾,需要運行ls-a 而不是ls:
$ls -a
4.在『.gitignore』中指定文件夾和文件的多種方法
.gitignore配置文件包含你不想在git系統中管理的文件和文件夾。在.gitignore中指定文件夾和文件的方法有很多種。首先,.gitignore中的#用於注釋(類似於Python中的#注釋)。
· 簡單文件名
# exclude dbinfo.php file in git system
dbinfo.php
· 模式匹配——「globbing」使用星號(*)
globbing是大多數Unix shell使用的通配符技術:
# exclude obj files
*.obj
· 指定不想排除的文件或文件夾
可以指定不想排除的文件或文件夾。當與團隊合作並希望重新聲明該文件或文件夾不應從git系統中排除時,這是很有用的做法:
# do not exclude the following configuration file
!config.php
· 文件相對路徑
# exclude the file in the current directory
/readme.txt# exclude all files in /pub/ directory
/pub/# exclude all txt files whose parent is docdoc/**/*.txt
5.空白信息選項
有時想在沒有信息的情況下進行提交,而信息卻又是提交的必要條件,可以使用--allow-empty-message選項:
$ git commit --allow-empty-mesage -m "" --- no commit message
6.分支層次結構
當分支中帶有斜槓(/)時,該分支將存儲為目錄層次結構:
Branch name
--> v1.5/feature-1
--> v1.5/fix-1--> v1.6/feature-2
--> v1.6/feature-3
--> v1.6/fix-1
7.顯示日誌
顯示git日誌有多種方法:
· pretty=online選項
$ git log --pretty=onelineOR$ git log --oneline
· 圖表選項
$ git log --online --graph
· 數字選項
$ git log --online --graph -5 // SHOW only 5 most recent commits
Git使用愉快!
留言點讚關注
我們一起分享AI學習與發展的乾貨
如轉載,請後臺留言,遵守轉載規範