1. 程式人生 > >學習git這一篇就夠了!!!

學習git這一篇就夠了!!!

#git命令操作 ## git工作流程 ![](https://img2020.cnblogs.com/blog/1246213/202010/1246213-20201007213140392-141173790.png) ## 本地庫操作 ### 初始化本地倉庫 + 初始化命令 git init ``` $ work % cd workspace $ workspace % mkdir WebService //建立資料夾 $ workspace % git init //初始化 Initialized empty Git repository in /Users/jack/work/workspace/.git/ $ workspace % ``` + 初始化後的效果 會在初始化後的目錄中生成一個.git隱藏資料夾 ``` $ workspace % cd .git $ .git % ls HEAD branches config description hooks info objects refs $ .git % ls -l total 24 -rw-r--r-- 1 jack staff 23 Sep 25 22:16 HEAD drwxr-xr-x 2 jack staff 64 Sep 25 22:16 branches -rw-r--r-- 1 jack staff 137 Sep 25 22:16 config -rw-r--r-- 1 jack staff 73 Sep 25 22:16 description drwxr-xr-x 13 jack staff 416 Sep 25 22:16 hooks drwxr-xr-x 3 jack staff 96 Sep 25 22:16 info drwxr-xr-x 4 jack staff 128 Sep 25 22:16 objects drwxr-xr-x 4 jack staff 128 Sep 25 22:16 refs $ .git % ``` 注意:.git目錄中的檔案不要刪除也不要修改,否則git不能正常工作。 ### 設定簽名 + 形式 使用者名稱:XXX Email地址:[email protected] + 作用 只是為了區分成員身份,不會給郵件地址傳送郵件。而且郵件地址可以是不存在地址。 + 注意 這裡的簽名和遠端倉庫的郵件地址密碼沒有任何關係 + 命令 1.專案級別/倉庫級別 僅在當前本地倉庫有效 git config user.name ***使用者名稱*** git config user.email ***郵箱地址*** ``` $ WebService % git config user.name njzy $ WebService % git config user.email [email protected] $ WebService % ``` 2.系統使用者級別 登入當前系統的使用者範圍 git config --global user.name ***使用者名稱*** git config --global user.email ***郵箱地址*** ``` $ WebService % git config --global user.name njzy_global $ WebService % git config --global user.email [email protected] $ WebService % ``` + 簽名儲存位置 1.專案級別 當前專案下的.git資料夾下的config檔案中。 檢視命令:cat .git/config ``` $ WebService % cat .git/config //檢視當前專案的簽名信息 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [user] name = njzy //被設定的專案使用者名稱 email = [email protected] //被設定的專案郵件地址 $ WebService % ``` 2.系統使用者級別 當前使用者資料夾下的.gitconfig檔案中。 檢視命令:cat .gitconfig ``` $ ~ % cd ~ //切換到當前使用者根目錄 $ ~ % pwd //檢視當前位置 /Users/jack $ ~ % cat .gitconfig //檢視全域性簽名信息 [user] name = njzy_global //被設定的全域性使用者名稱 email = [email protected] //被設定的全域性郵件地址 $ ~ % ``` + 專案級別和系統使用者級別的簽名的優先(就近原則) 1.> 兩個都設定情況下 專案級別優先於系統使用者級別 2.> 只設定系統使用者級別簽名 以系統使用者級簽名別為準 3.> 只設定專案級別 以專案級別為準 4.> 兩個都沒有設定的話不允許。 ### 檢視git狀態 + 作用 確認git的暫存區,本地倉庫的情況。 + 命令 git status ### 新增操作 + 目的 把內容從工作區新增到暫存區,也叫追蹤。 + 命令 1.新增單個檔案 git add 檔名 2.新增多個檔案 1.> git add 檔名1 檔名2 檔名3 .... 2.> git add -A 3.> git add . 詳細參考git幫助文件 ``` usage: g