git基本操作命令

git remote add <遠(yuǎn)程分知名>  <倉庫地址> //這條命令是添加遠(yuǎn)程倉庫與本地關(guān)聯(lián)
例如:git remote add origin https://github.com/LeiJames/Demo.git

git remote -v 查看遠(yuǎn)端信息 

git branch --set-upstream-to=origin/<branch> master 
git push --set-upstream origin master//設(shè)置pull時(shí)候或者push時(shí)候直接的關(guān)聯(lián)意思說以后直接可以用git push 或者git pull命令不用再加參數(shù)了

git pull origin master --allow-unrelated-histories//出現(xiàn)fatal: refusing to merge unrelated histories的解決辦法

 //將branch-name分支追蹤遠(yuǎn)程分支origin/branch-name
 git branch --set-upstream branch-name origin/branch-name

// 設(shè)置當(dāng)前分支跟蹤遠(yuǎn)程分支origin/serverfix
git branch -u origin/serverfix

git branch -D <遠(yuǎn)程分支名>//刪除遠(yuǎn)程分支
git checkOut -b <本地分支名><origin/master>//切換到master分支并在本地建立一個(gè)分支
git push origin --delete (后面加分支名) 刪除遠(yuǎn)程分支
git fetch -p 刪除本地分支在(遠(yuǎn)程和本地同名但是遠(yuǎn)程不存在的)
git stash 是把當(dāng)前工作區(qū)的內(nèi)容和緩存區(qū)的內(nèi)容存到棧里面  可以同git stash pop 取出來
git push origin 本地分支名:遠(yuǎn)程分支名 (將本地分支推送到遠(yuǎn)程)
撤銷相關(guān) 
git reset --hard ORIG_HEAD 將本地文件回滾到遠(yuǎn)程最新的HAED狀態(tài)
 
 出現(xiàn).DS store沖突的解決方法 
 git clean -d -fx "" 刪除git不在追蹤的文件

至于這幾個(gè)參數(shù):

--mixed

意思是:不刪除工作空間改動(dòng)代碼,撤銷commit,并且撤銷git add . 操作

這個(gè)為默認(rèn)參數(shù),git reset --mixed HEAD^ 和 git reset HEAD^ 效果是一樣的。

--soft

不刪除工作空間改動(dòng)代碼,撤銷commit,不撤銷git add .

--hard

刪除工作空間改動(dòng)代碼,撤銷commit,撤銷git add .

注意完成這個(gè)操作后,就恢復(fù)到了上一次的commit狀態(tài)。

文件改動(dòng)時(shí)候是未暫緩區(qū)(工作區(qū)),git add .是將文件加入到暫緩區(qū), git commit -m是將文件信息添加到數(shù)據(jù)庫

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

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

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