羅杰?杜德勒編寫整理了一個(gè)不錯(cuò)的git - 簡(jiǎn)易指南抗斤,可以查看學(xué)習(xí)。網(wǎng)上也有很多內(nèi)容畜伐,沒記住的馍惹,要用時(shí)搜一下就好了。
另外,我在github有放一個(gè)簡(jiǎn)單的《7-Git入門指南》的 PPT万矾,可以一并查看悼吱,主要說明的是:
- Git 是什么?
- Git 簡(jiǎn)明指南補(bǔ)充說明
- Git 常用指令(本文正文)
- 使用 Git 一般開發(fā)規(guī)范
- Git Client GUI 及在 VS code 中使用 Git
此處只是列示一些可能常用的 git 指令:
配置使用 Git 的賬號(hào)密碼:
git config --global user.name "Your Name"
git config --global user.email email@example.com
初始化一個(gè) Git 倉庫:
git init
添加文件到 Git 倉庫良狈,分兩步:
添加到暫存區(qū):
git add <file> #注意后添,可反復(fù)多次使用,添加多個(gè)檔薪丁;
提交到倉庫
git commit -m <message>遇西。
查看工作區(qū)的狀態(tài):
git status。
可以查看修改內(nèi)容:
git diff
關(guān)聯(lián)一個(gè)遠(yuǎn)程庫:
git remote add origin git@server-name:path/repo-name.git严嗜;
關(guān)聯(lián)后粱檀,使用命令第一次推送 master 分支的所有內(nèi)容:
git push -u origin master
此后,每次本地提交后漫玄,推送最新修改茄蚯;
git push origin master
要克隆一個(gè)倉庫,首先必須知道倉庫的地址称近,然后使用
git clone git@server-name:path/repo-name.git第队。
查看分支:
git branch
創(chuàng)建分支:
git branch <name>
切換分支:
git checkout <name>
創(chuàng)建+切換分支:
git checkout -b <name>
合并某分支到當(dāng)前分支:
git merge <name>
刪除分支:
git branch -d <name>
看到分支合并圖:
git log –graph
查看遠(yuǎn)程庫信息:
git remote -v;
從本地推送分支
git push origin <branch-name>刨秆,
抓取遠(yuǎn)程的新提交凳谦;
git pull
在本地創(chuàng)建和遠(yuǎn)程分支對(duì)應(yīng)的分支,使用
git checkout -b <branch-name> origin/<branch-name> # 本地和遠(yuǎn)程分支的名稱最好一致衡未;
建立本地分支和遠(yuǎn)程分支的關(guān)聯(lián)
git branch --set-upstream branch-name origin/branch-name尸执;