前言
1、Git的主要特點(diǎn)是穩(wěn)定,運(yùn)行快速,獨(dú)立的環(huán)境及高效的合并。
2、Git處理的對象有5個:
工作目錄 working directory
預(yù)備區(qū) staging area
提交歷史 commit history
開發(fā)分支 developmnent branches
遠(yuǎn)程庫 remote
3、Git的主要操作分為5類:
配置Configure
記錄 Recording
撤銷 Undoing
分支 Branch
遠(yuǎn)端remote
1、Git配置
此處簡單,配置就是git-config:
git config --global user.name spiritme
git config --global user.email abst.proc.do@qq.com
最后可以統(tǒng)覽全部的信息:
$ git config --list
user.name=AbstProcDo
user.email=abst.proc.do@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:AbstProcDo/ORG.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.develop.remote=origin
branch.develop.merge=refs/heads/develop
branch.develop.pushremote=origin
2、Git記錄變更
Git commit changes 是git操作最重要的環(huán)節(jié),全部的命令總結(jié)如下:
# 預(yù)備區(qū)
git add # 添加文件到預(yù)備區(qū)
git rm --cached # 從預(yù)備區(qū)刪除文件,此操作并不刪除工作目錄下的文件
# 檢測預(yù)備區(qū)域
git status
git diff
git diff --cached
# 提交
git commit
# 檢測提交記錄
git log --oneline
git log since until
# 打標(biāo)簽
git tag -a v0.1 -m 'unstable release'
3、Git撤銷變更
變更的撤銷包含三個方面,一是在工作區(qū),二是在預(yù)備區(qū),三是在整個commit history。這些方面git有各種異常復(fù)雜的命令,我們化繁為簡,去蕪存菁。
# 跳轉(zhuǎn)到最近的工作區(qū)
git reset --hard HEAD
git clean –f
# 將單個文件拉入到工作區(qū)
git checkout HEAD <file>
# 撤銷預(yù)備區(qū)的文件
git reset HEAD <file> #注意區(qū)分 git reset –-hard HEAD
# 撤銷commit
git reset HEAD~1
git revert <commit-id>
git commit –amend
4、Git分支
分支是git的菁華之所在,神奇的幫助我們在平行宇宙的時間線中遨游。
# 查看分支
git branch
# 創(chuàng)建分支
git branch a-new-branch # 文件中查看.git/refs/heads/<name>
# 刪除分支
git branch -d branch-name
git branch -D branch-name # 當(dāng)心
# 跳轉(zhuǎn)到分支
git checkout branch
# 創(chuàng)建與跳轉(zhuǎn)兩步合一
git checkout -b branch
# 甚至可以直接使用git checkout tag(id) 到 detached heads中
# 合并分支
git merge
# 變基
git rebase branch
git rebase -i branch
5、Git遠(yuǎn)程
git-remote命令與世界構(gòu)建關(guān)聯(lián)。
# 查看remote
git remote
git remote -v
# 添加remote
git remote add
# 刪除remote
git remote rm
# 獲取遠(yuǎn)端倉庫
git fetch
# 獲取全部分支
git branch -r
# 查看遠(yuǎn)端分支的狀態(tài)
git log master..origin/master
# 合并遠(yuǎn)端分支
git merge origin/master
git rebase origin/master
git pull origin/master
git push <remote> <branch>
-
更多測試技術(shù)分享、學(xué)習(xí)資源以及一些其他福利可關(guān)注公眾號:【Coding測試】獲取:
`Coding測試
