git 基本操作

2022-08-23 05:09:14 字數 2051 閱讀 3724

【git 刪除本地分支】

git branch -d br

【git 刪除遠端分支】

git push origin :br  (origin 後面有空格)

git**庫回滾: 指的是將**庫某分支退回到以前的某個commit id

【本地**庫回滾】:

git reset --hard commit-id :回滾到commit-id,講commit-id之後提交的commit都去除

git reset --hard head~3:將最近3次的提交回滾

【遠端**庫回滾】:

這個是重點要說的內容,過程比本地回滾要複雜

應用場景:自動部署系統發布後發現問題,需要回滾到某乙個commit,再重新發布

原理:先將本地分支退回到某個commit,刪除遠端分支,再重新push本地分支

操作步驟:

1、git checkout the_branch

2、git pull

3、git branch the_branch_backup //備份一下這個分支當前的情況

4、git reset --hard the_commit_id //把the_branch本地回滾到the_commit_id

5、git push origin :the_branch //刪除遠端 the_branch

6、git push origin the_branch //用回滾後的本地分支重新建立遠端分支

7、git push origin :the_branch_backup //如果前面都成功了,刪除這個備份分支

如果使用了gerrit做遠端**中心庫和code review平台,需要確保操作git的使用者具備分支的push許可權,並且選擇了 force push選項(在push許可權設定裡有這個選項)

另外,gerrit中心庫是個bare庫,將head預設指向了master,因此master分支是不能進行刪除操作的,最好不要選擇刪除master分支的策略,換用其他分支。如果一定要這樣做,可以考慮到gerrit伺服器上修改head指標。。。不建議這樣搞

【git 刪除本地分支】

git branch -d br

【git 刪除遠端分支】

git push origin :br  (origin 後面有空格)

git**庫回滾: 指的是將**庫某分支退回到以前的某個commit id

【本地**庫回滾】:

git reset --hard commit-id :回滾到commit-id,講commit-id之後提交的commit都去除

git reset --hard head~3:將最近3次的提交回滾

【遠端**庫回滾】:

這個是重點要說的內容,過程比本地回滾要複雜

應用場景:自動部署系統發布後發現問題,需要回滾到某乙個commit,再重新發布

原理:先將本地分支退回到某個commit,刪除遠端分支,再重新push本地分支

操作步驟:

1、git checkout the_branch

2、git pull

3、git branch the_branch_backup //備份一下這個分支當前的情況

4、git reset --hard the_commit_id //把the_branch本地回滾到the_commit_id

5、git push origin :the_branch //刪除遠端 the_branch

6、git push origin the_branch //用回滾後的本地分支重新建立遠端分支

7、git push origin :the_branch_backup //如果前面都成功了,刪除這個備份分支

如果使用了gerrit做遠端**中心庫和code review平台,需要確保操作git的使用者具備分支的push許可權,並且選擇了 force push選項(在push許可權設定裡有這個選項)

另外,gerrit中心庫是個bare庫,將head預設指向了master,因此master分支是不能進行刪除操作的,最好不要選擇刪除master分支的策略,換用其他分支。如果一定要這樣做,可以考慮到gerrit伺服器上修改head指標。。。不建議這樣搞

Git基本操作

1.初始化倉庫 git init 2.配置作者資訊 git config global user.email youremail corp.com git config global user.name yourname 3.新增檔案到暫存區 git add git add 新增所有檔案到暫存區 4...

git基本操作

1.先建乙個資料夾 mikdir gittest 這時就會有乙個gittest資料夾,cd gittest 進入這個資料夾 ls一下,就會看到gittest下沒有東西 2.生成乙個git git init cat git 顯示一下所有git 3.建乙個檔案 touch readme.md 這時git...

Git基本操作

21 nov,錦州 同生活中的許多偉大事件一樣,git 誕生於乙個極富紛爭大舉創新的年代。linux 核心開源專案有著為數眾廣的參與者。絕大多數的 linux 核心維護工作都花在了提交補丁和儲存歸檔的繁瑣事務上 1991 2002年間 到 2002 年,整個專案組開始啟用分布式版本控制系統 bitk...