1.checkout
$ git checkout -b hotfix
Switched to a new branch 'hotfix'
2.reset
reset Reset current HEAD to the special state.
git reset 可以將提交的內(nèi)容重置。--mixed 是默認(rèn)操作。 --soft 重置之后不會(huì)讓本地的代碼消失。 --hard 重置之后會(huì)讓本地代碼消失。
git reset --hard HEAD^^ 小角個(gè)數(shù)代表重置次數(shù)。執(zhí)行reset操作之后,HEAD和遠(yuǎn)程倉(cāng)庫(kù)不一致,需要解決沖突才能push。
以上命令已經(jīng)無(wú)用,以下命令才有用。2021-06-21
git reset --soft HEAD~1
3.fetch
git fetch origin 遠(yuǎn)程分支xxx:本地分支xxx
git fetch [<options>] [<repository> [<refspec>…]]
git log FETCH_HEAD //查看fetch日志
4.rebase和merge
rebase和merge都是用來(lái)合并分支的命令。
rebase只是合并內(nèi)容,不會(huì)合并提交歷史。merge會(huì)把提交歷史都合并。
git checkout featureA
git merge master
git checkout featureA
git rebase master
它會(huì)把整個(gè)featureA的分支直接移到現(xiàn)在master分支的后面。
git rebase origin/dev
合并遠(yuǎn)程分支到當(dāng)前分支。
5.stash
stash將本地的變化緩存起來(lái)。stash pop將代碼從緩存中彈出來(lái)。
可以有效利用該命令,合并遠(yuǎn)程代碼。
refusing to merge unrelated histories

需要執(zhí)行g(shù)it pull origin master --allow-unrelated-histories將兩個(gè)分支強(qiáng)行合并
有時(shí)候,git pull的時(shí)候提示失敗,可以用git fetch之后,再git rebase
6.push
git push origin feature-branch:feature-branch //推送本地的feature-branch(冒號(hào)前面的)分支到遠(yuǎn)程origin的feature-branch(冒號(hào)后面的)分支(沒(méi)有會(huì)自動(dòng)創(chuàng)建)
查看本地分支:
git branch
查看遠(yuǎn)程分支:
git branch -a
7.更新代碼
以下命令的效果,相當(dāng)于fetch+rebase,-r的意思是rebase
git pull -r origin oa-cloud
沒(méi)事的時(shí)候可以看看:https://www.cnblogs.com/qcloud1001/p/9796750.html
存儲(chǔ)密碼,避免多次輸入
You can use the git-credential-store via
git config credential.helper store
which stores your password unencrypted in the file system
8.關(guān)聯(lián)GitHub倉(cāng)庫(kù)

9.開(kāi)發(fā)流程

10.不merge某個(gè)文件(有問(wèn)題)
http://www.itdecent.cn/p/09b546b936a7
11.delete branch
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName
12.拉取遠(yuǎn)程分支并創(chuàng)建本地分支
方法一
使用如下命令:
git checkout -b 本地分支名x origin/遠(yuǎn)程分支名x
使用該方式會(huì)在本地新建分支x,并自動(dòng)切換到該本地分支x。
采用此種方法建立的本地分支會(huì)和遠(yuǎn)程分支建立映射關(guān)系。
方式二
使用如下命令:
git fetch origin 遠(yuǎn)程分支名x:本地分支名x
使用該方式會(huì)在本地新建分支x,但是不會(huì)自動(dòng)切換到該本地分支x,需要手動(dòng)checkout。
采用此種方法建立的本地分支不會(huì)和遠(yuǎn)程分支建立映射關(guān)系。
參考鏈接:https://juejin.cn/post/6844903539324485639
https://www.cnblogs.com/qyf404/p/git_push_local_branch_to_remote.html
https://www.cnblogs.com/springbarley/archive/2012/11/03/2752984.html
https://www.huaweicloud.com/articles/e295e93d1a0f08102fe61426ef4997f3.html
https://www.cnblogs.com/qcloud1001/p/9796750.html
https://www.freecodecamp.org/news/how-to-delete-a-git-branch-both-locally-and-remotely/
https://devconnected.com/how-to-undo-last-git-commit/#:~:text=The%20easiest%20way%20to%20undo,removed%20from%20your%20Git%20history.