生產(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