git 常用命令

Git 創(chuàng)建分支

Git checkout -b 分支名稱

Git branch 查看所有分支

git merge login 合并分支 login 到當前分支

git push --set-upstream origin login 提交新的分支

git push origin login 提交代碼到 login 分支

要將A分支的一個commit合并到B分支:

首先切換到A分支

git checkout A

git log

找出要合并的commit ID :

commit 331cdbf28fba8343511ecbd29e704611bae70298

然后切換到B分支上

git checkout B

git cherry-pick 331cdbf28fba8343511ecbd29e704611bae70298

這樣就將A分支的某個commit合并到了B分支了

希望保留本地的修改,pull之后,修改依然存在

git stash

git pull

git stash pop

解析:

git stash: 將改動藏起來

git pull:用新代碼覆蓋本地代碼

git stash pop: 將剛藏起來的改動恢復(fù)

這樣操作的效果是在最新的倉庫代碼的基礎(chǔ)仍保留本地的改動

git stash # save uncommitted changes

pull, edit, etc.

git stash list # list stashed changes in this git

git show stash@{0} # see the last stash

git stash pop # apply last stash and remove it from the list

git stash apply stash@{2}

git stash --help # for more info

這種問題是因為VSCode中,花括號在 PowerShell 中被認為是代碼塊執(zhí)行標識符,若想正常使用,可用反引號 進行轉(zhuǎn)義:stash@{0’}

git branch -r****:查看所有遠程分支

git checkout 遠程分支名:拉取遠程分支并同時創(chuàng)建對應(yīng)的本地分支

git checkout master

git pull

git merge --no-commit --no-ff develop

要強制使用本地分支,使用git branch -D + 分支名稱的命令。

git branch -d test_branch來刪除本地分支,

git checkout -b myRelease origin/Release

作用是checkout遠程的Release分支,在本地起名為myRelease分支,并切換到本地的myRelase分支

git取消合并<u>#</u>

git merge --abort

導(dǎo)出提交記錄

git log --pretty=format:"%ai , %an: %s" --since="400day ag" --encoding="GBK" >> ~/Desktop/commit-employee-src.csv

1. git刪除遠程分支

git push origin --delete [branch_name]

2. 刪除本地分支區(qū)別

git branch -d 會在刪除前檢查merge狀態(tài)(其與上游分支或者與head)。

git branch -D 是git branch --delete --force的簡寫,它會直接刪除。

git remote add itiaoling <u>http://code.itiaoling.com/development/isc/frontend/oc-web.git</u>

在這里沒有看到我們想要的分支,先獲取所有分支:

git fetch

1、git update-index --assume-unchanged ${文件路徑}

2、讓git不再跟蹤{文件路徑}的更新了;當項目開發(fā)完成后又想將該配置文件的修改更新提交至遠程倉庫,就解除不跟蹤設(shè)置,使用命令:git update-index --no-assume-unchanged{文件路徑},即可使git再次跟蹤${文件路徑}

.在工作區(qū)修改,但并未提交到暫存區(qū)(即并沒有add)

對于單個文件的撤銷修改而言,使用下面方法。

$ git checkout -- 文件名

git 刪除某個提交

git reset --soft HEAD~n ,撤銷最近n個提交,變成add狀態(tài)

git stash 暫存代碼

git reset --hard HEAD~1 刪除前1一個提交

git unstash 取出代碼

git commit 重新提交代碼

git push -f 強制推送到遠程

1. 本地分支重命名(還沒有推送到遠程)

|

1

|

git branch -m oldName newName

|

2. 遠程分支重命名 (已經(jīng)推送遠程-假設(shè)本地分支和遠程對應(yīng)分支名稱相同)

a. 重命名遠程分支對應(yīng)的本地分支

|

1

|

git branch -m oldName newName

|

b. 刪除遠程分支

|

1

|

git push --delete origin oldName

|

c. 上傳新命名的本地分支s

|

1

|

git push origin newName

|

d.把修改后的本地分支與遠程分支關(guān)聯(lián)

|

1

|

git branch --set-upstream-to origin/newName

|

git fetch origin master //僅同步遠程master分支到本地

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

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

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