學(xué)習(xí)資料來自于 廖雪峰的官方網(wǎng)站
初始化git信息
git config --global user.name "Your name"
git config --global user.emal "email@example.com"
生成git目錄
git init
灰常重要
我實在是看不下去了利诺,一會兒暫存區(qū)一會兒版本庫的酝蜒,請先分清概念键闺,經(jīng)過我的實驗挎挖,提> 交代碼的更改一共分2個階段种吸。
1).從工作目錄,提交到stage瓮钥。
2).從stage提交到master式散。
從工作目錄提交到stage,需要用add或者rm命令惧眠,只提交到stage籽懦,而沒有提交到>master,是不會自動同步到master的氛魁。
從stage提交到master用commit命令暮顺。
退回也是要分兩步,一個是從master退回到stage秀存,然后再從stage退回到工作目錄捶码。
對于還沒有提交到stage的,可以從stage用checkout命令退回或链,這一步會取stage中的文件狀態(tài)宙项,覆蓋掉工作目錄中文件的狀態(tài),跟master完全沒關(guān)系株扛。
對于已經(jīng)到達(dá)stage的尤筐,想把state中的文件狀態(tài)用master中的覆蓋掉,就用reset命令洞就,這>樣就把stage中修改用master的狀態(tài)覆蓋掉了盆繁,完全跟工作目錄沒關(guān)系
文件加入git控制
-加入當(dāng)個文件
git add README.md
-加入全部文件
git add .
git 文件提交
git commit -m 'comment'
查看更改的狀態(tài)
git status
查看文件是否不一致
git diff README.md
相對于第一次提交到目前的內(nèi)容的變化記錄
git log
回滾commit到master的內(nèi)容
git reset --hard head ^
git reset --hard head^^
git reset --hard head ~2
git reset --hard head 版本號名稱
查看每一次我們對文件操作的操作
git reflog
從stage中取文件來替換現(xiàn)在工作區(qū)間的文件
git checkout -- README.md
從master中取文件來代替在stage中的文件
git reset HEAD README.md
將stage中的文件刪除
git rm README.md
然后通過commit 將這個變更推送到本地的master
本地私鑰和公鑰生成指令
ssh-keygen -t rsa -b 4096 -C 'yourmail@mail.com'
將本地的git和遠(yuǎn)程的關(guān)聯(lián)起來
git remote origin add git@github.com:andrewchen1/Python101.git
將本地的分支和遠(yuǎn)程的master分支關(guān)聯(lián),并且將
git push -u origin master
之后就可以通過
git push origin master 進(jìn)行推送
復(fù)制遠(yuǎn)程倉庫的內(nèi)容
git clone git@github.com:andrewchen1/Python101.git
or
git clone https://github.com/andrewchen1/Python101.git
創(chuàng)建分支
git checkout -b dev
which equal to
git branch dev
git checkout dev
之后我們所有的更改都在dev 這個分支上面了
將支分支上的內(nèi)容合并到主分支上
-將分支切換到主分支上
git checkout master
-合并分支
git merge dev
刪除分支
git branch -d dev
BUG 分支
將內(nèi)容暫存起來
-git stash
-git checkout master
-git checkout -b issue-101
-git add README.md
-git add commit -m 'fix the bug issue'
測試好了之后
-git checkout master
-git merge issue-101
-git branch -d issue-101
-git chekout dev
-git stash apply
or
-git stash pop
來恢復(fù)
其中可以通過
git stash list 查看stash的內(nèi)容
強(qiáng)制刪除分支
在分支有commit的情況下想要強(qiáng)制刪除的話
git branch -D 'FEATURE101'
創(chuàng)建標(biāo)簽
git tag v1.0_or_somethinge_else
這時候給創(chuàng)建的標(biāo)簽是放在上次的commit上面的
git tag tag_name 6224937
6224937是歷史某次commit 的id
還可以創(chuàng)建帶有說明的標(biāo)簽
git tag -a v0.1 -m 'version 0.1 released' 3628164
checkout tag
git checkout tags/<tag_name> -b <branch_name>
$ git clone will give you the whole repository.
After the clone, you can list the tags with $ git tag -l and then checkout a specific tag:
$ git checkout tags/<tag_name>
Even better, checkout and create a branch (otherwise you will be on a branch named after the revision number of tag):
$ git checkout tags/<tag_name> -b <branch_name>