git
人生不能重來,git 可以!
安裝
設定使用者
git config --global user.name "My Name"
設定信箱
git config --global user.email "myemail@example.com"
初始化
git init
提交第一個版本
先建立專案結構,參考 建議專案結構
建立完畢後,執行
git add .
將目前檔案加入 stage change
等待提交
執行提交
git commit -m "my first commit."
查看紀錄
git log
查看紀錄明細
git log --stat
圖形化顯示
git log --stat --pretty=short --graph
查看目前變化
git status
放棄目前變化
單一檔案
git restore <file>
全部檔案
git restore .
目前變化放入等待提交 stage change
單一檔案
git add <file>
全部檔案
git add .
提交
git commit -m "add reset style."
跳到特定版本
保留檔案跳版本,未納入版本的檔案會變成未提交狀態
git reset <commit hash>
不保留檔案跳版本,未納入版本的檔案會直接消失
連同提交紀錄也會消失,但是如果知道
commit hash
還是可以恢復
git reset --hard <commit hash>
提交線上資源庫
- 註冊
- 建立資源庫 (
Respositories
)
增加線上資源庫位置
git branch -M main
git remote add origin https://github.com/<account>/<repositories>.git
提交
git push -u origin main
過程會要求登入
建立 readme.md
說明專案使用,使用 markdown
格式
readme.md
# Frontend Project
This is my first frontend project.
git add .
git commit -m "add readme."
git push -u origin main
複製資源庫 clone
從現有資源庫複製一份出來,如無指定資料夾名稱,會自動產生 repositories
名稱的資料夾
不要自己建立資料夾!
git clone https://github.com/<account>/<repositories>.git <custom dir>
同步資源庫 pull
多人開發時,可能資源庫與你現在的有差異,這時候可以將線上資源庫同步下來
git pull origin main