git 用法

生產(chǎn)應(yīng)用

生成分枝
git checkout -b master-zsl

版本管理

場(chǎng)景1:當(dāng)你改亂了工作區(qū)某個(gè)文件的內(nèi)容,想直接丟棄工作區(qū)的修改時(shí),用命令
git checkout -- file。

場(chǎng)景2:當(dāng)你不但改亂了工作區(qū)某個(gè)文件的內(nèi)容,還添加到了暫存區(qū)時(shí),想丟棄修改,分兩步,第一步用命令git reset HEAD file,就回到了場(chǎng)景1,第二步按場(chǎng)景1操作。

場(chǎng)景3:已經(jīng)提交了不合適的修改到版本庫時(shí),想要撤銷本次提交,參考版本回退一節(jié),不過前提是沒有推送到遠(yuǎn)程庫。
git reset --hard HEAD^/git reset --hard 3628164
與git log /git reflog同時(shí)使用
git log
git log --graph --pretty=oneline --abbrev-commit
git reflog


合并多個(gè)commit 為一個(gè)

1、在log中選中一個(gè) Reset Current branch to here
2、git push
如果出現(xiàn)“hint: Updates were rejected because the tip of your current branch is behind”錯(cuò)誤
2.1、刪除遠(yuǎn)端分支后,重新push(其它相關(guān)合并分支 dev-yufabu要重新刪除)
2.2、新建分支,將修改merge到新分支后,在新分支push


常用操作

--生成ssh key
ssh-keygen -t rsa -C "zhangshaolin@jd.com"

1、本地新建git倉(cāng)庫
git init
2、在github-new repository
3、推送github
git remote rm origin
git remote add origin https://github.com/lesline/learngit
git push -u origin master
git push origin dev


同步代碼
1、獲取遠(yuǎn)程代碼
git branch --set-upstream dev origin/dev
git pull
2、沖突
git add 
git commit

--遠(yuǎn)程庫clone
git clone https://github.com/lesline/learngit

--新建分支
git checkout -b dev
git branch dev
git checkout dev

--切換回master分支
git checkout master

--查看
git branch
git log --graph --pretty=oneline --abbrev-commit

分枝管理

Git鼓勵(lì)大量使用分支:

查看分支: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 merge --no-ff -m "merge with no-ff" dev


git 原理

https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-Git-%E5%9F%BA%E7%A1%80

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容