git常用指令 github版本回退 reset

2022-09-11 18:06:11 字數 2078 閱讀 6227

1:git reset –mixed:此為預設方式,不帶任何引數的git reset,即時這種方式,它回退到某個版本,只保留原始碼,回退commit和index資訊

2:git reset –soft:回退到某個版本,只回退了commit的資訊,不會恢復到index file一級。如果還要提交,直接commit即可

git reset head^

git reset head^ a.py

git reset –soft head~3

git reset –hard origin/master

git reset 057d

git revert head

如果我們某次修改了某些內容,並且已經commit到本地倉庫,而且已經push到遠端倉庫了

這種情況下,我們想把本地和遠端倉庫都回退到某個版本,該怎麼做呢?

前面講到的git reset只是在本地倉庫中回退版本,而遠端倉庫的版本不會變化

這樣,即時本地reset了,但如果再git pull,那麼,遠端倉庫的內容又會和本地之前版本的內容進行merge

這並不是我們想要的東西,這時可以有2種辦法來解決這個問題:

1:直接在遠端server的倉庫目錄下,執行git reset –soft 10efa來回退。注意:在遠端不能使用mixed或hard引數

2:在本地直接把遠端的master分支給刪除,然後再把reset後的分支內容給push上去,如下:

複製**

git branch old_master

git push origin old_master:old_master

git reset –hard bae168

git push origin :master

git push origin master

複製**

在刪除遠端master分支時,可能會有問題,見下:

error: by default, deleting the current branch is denied, because the next

error: 'git clone' won't result

in any file checked out, causing confusion.

error:

error: you can set 'receive.denydeletecurrent' configuration variable to

error: 'warn' or 'ignore' in

the remote repository to allow deleting the

error: current branch, with

orwithout a warning message.

error:

error: to squelch this message, you can set

itto 'refuse'.

error: refusing to delete the current branch: refs/heads/master

to [email protected]:gitosis_test

! [remote rejected] master (deletion of

the current branch prohibited)

error: failed to push some refs to '[email protected]:gitosis_test'

這時需要在遠端倉庫目錄下,設定git的receive.denydeletecurrent引數

git receive.denydeletecurrent warn

然後,就可以刪除遠端的master分支了

雖然說有以上2種方法可以回退遠端分支的版本,但這2種方式,都挺危險的,需要謹慎操作……

github常用指令

總結一下ubuntu下github常用的命令,設定部分跳過,假設repository的名字叫hello world 1.建立乙個新的repository 先在github上建立並寫好相關名字,描述。cd hello world 到hello world目錄 git init 初始化 git add ...

Github常用指令

名稱 作用cd 進入到乙個目錄 pwd顯示當前所在的目錄 ls將目錄裡的每個檔案列出來 git init 把這個目錄變成可管理的空倉庫 git status 檢視當前倉庫的狀態 git add 往倉庫裡加檔案 git rm cached 刪除倉庫中不需要的東西 git commit 提交到倉庫 gi...

Github常用指令

ssh方法git init ssh keygen t rsa c yourname 輸入路徑後開啟id rsa.pub複製到倉庫 setting deploy keys,allow write access記得打勾 git remode add 遠端倉庫命名 ssh 例如 git remote ad...