git delete a specified commit

There are 3 ways to reset the command:

1: git reset -mixed: This is the default mode, git
reset without any parameters , even in this mode, it rolls back to a certain version, only keeps the source code, and rolls back commit and index information

2: git reset -soft: Roll back to a certain version, only the commit information is rolled back, and will not be restored to the index
file level. If you still want to submit, just commit directly

3: git reset -hard: completely roll back to a certain version, and the local source code will also become the content of the previous version

git reset only rolls back the version in the local warehouse, and the version of the remote warehouse will not change.
Take deleting the master branch as an example

#新建一个备份的分支,数据无价
git branch old_master

#提交本地当前的文件到新建的分支
git push origin old_master:old_master

#本地可以彻底恢复到你想恢复到的版本了
git reset --hard 58093e1355716f0f861b64f1c3dfe59242be28f7

#在web端settings页面,修改默认分支为新建的分支,可以删除远程分支了
git push origin :master

#如果出现! [remote rejected] master (deletion of the current branch prohibited),说明没有设置远程的默认分支,没有权限删除,请在web端settings页面,修改默认分支为新建的分支

#进行到这里,远程的master分支已经删除成功
#重新提交本地文件到master分支(此时会自动新建master分支)
git push origin master

#再体验一下删除分支
git push origin :old_master

 

Guess you like

Origin blog.csdn.net/xifei66/article/details/104959592