1. 安裝git
ubuntu:suao apt-get install git-core
Windows:軟件git for windows
2. 配置身份
這樣Git就可以知道是誰(shuí)提交的了。Linux:終端下。Windows:Git Bash下
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
3. 創(chuàng)建倉(cāng)庫(kù)
在項(xiàng)目根文件夾下聂示,輸入git init
倉(cāng)庫(kù)創(chuàng)建完成后彬檀,會(huì)生成一個(gè)隱藏的.git
文件(用來(lái)記錄所有Git操作)∷萜可通過(guò)ls -al
查看文件夾中的文件情況虐秋。
4. 提交本地代碼
添加操作:所有文件git add .
,單獨(dú)文件git add filename
发乔。
提交:git commit -m "describe the commit"
進(jìn)階操作
- 忽略文件
.gitignore
文件中操作熟妓。 - 查看修改內(nèi)容
狀態(tài):git status
修改內(nèi)容:git diff
只看某文件修改內(nèi)容:git diff path/filename
- 撤銷未提交的修改
git checkout path/filename
:適用于未add
git reset HEAD path/filename
:取消add
- 查看提交記錄
查看歷史記錄:git log
查看某次記錄詳情:git log commitId -1 -p
- 分支
創(chuàng)建分支:git branch newbranchname
查看所有分支:git branch
切換分支:git checkout newbranch
分支合并:git merge newbranchname
在master
分支下進(jìn)行合并,把另一個(gè)分支修改內(nèi)容同步到master
分支栏尚。
刪除分支:git branch -D newbranchname
- 與github協(xié)作
下載到本地:git clone https://github.com/example/test.git
本地修改后同步:git push origin master
github修改后同步到本地:git pull origin master