1.回滚到指定版本操作命令
1.git reset --hard bcf27bc
2.git push origin master --force
测试记录
➜ Fish git:(test) git checkout -b test03 origin/test // 创建切换到test03分支拉取远程test分支代码
➜ [修改分支代码后]
➜ Fish git:(test03) git add .
➜ Fish git:(test03) ✗ git commit -m "[test03]"
➜ Fish git:(test03) git push origin test03 // 推送到远程test03分支
➜ Fish git:(test03) git push origin test03:master // 推送到远程master分支
➜ [test03]代码和[master]分支代码一致
➜ Fish git:(test03) git checkout master
➜ Fish git:(master)git pull origin master // 拉取远程master分支代码
➜ Fish git:(master)git reflog
35716d9 (origin/test1, origin/test, test) HEAD@{4}: commit: [5]
9c9f912 HEAD@{5}: commit: [4]
74d198d HEAD@{6}: commit: [3]
73f1bef HEAD@{7}: commit: [2]
521e0f9 HEAD@{8}: commit: [1]
bcf27bc HEAD@{9}: checkout: moving from master to test
bcf27bc HEAD@{10}: commit: [插件发布001]
master需要发版[插件发布001]版本,执行回滚命令
➜ Fish git:(master) git reset --hard bcf27bc
HEAD is now at bcf27bc [插件发布001]
➜ Fish git:(master) git push origin master --force
我提交了5个记录都没了,good job~ 就是我想要的
commit: [5]
commit: [4]
commit: [3]
commit: [2]
commit: [1]
我草,代码没了?有没有后悔药吃~
➜ Fish git:(master)git reflog
bcf27bc (HEAD -> master, origin/master) HEAD@{0}: reset: moving to bcf27bc
37b4ab0 (origin/test03, test03) HEAD@{1}: pull --no-stat -v --progress origin master: Fast-forward
bcf27bc (HEAD -> master, origin/master) HEAD@{2}: checkout: moving from test03 to master
37b4ab0 (origin/test03, test03) HEAD@{3}: commit: [test03]
35716d9 (origin/test1, origin/test, test) HEAD@{4}: checkout: moving from test to test03
35716d9 (origin/test1, origin/test, test) HEAD@{5}: commit: [5]
9c9f912 HEAD@{6}: commit: [4]
74d198d HEAD@{7}: commit: [3]
73f1bef HEAD@{8}: commit: [2]
521e0f9 HEAD@{9}: commit: [1]
bcf27bc (HEAD -> master, origin/master) HEAD@{10}: checkout: moving from master to test
bcf27bc (HEAD -> master, origin/master) HEAD@{11}: commit: [插件发布001]
➜ Fish git:(master)git reset 37b4ab0 --hard
➜ Fish git:(master)git push origin master --force
2.创建远程分支
test 本地当前分支
test1 创建的远程分支
当前[test]分支代码提交到远程[test1]分支
git push origin test:test1
网友评论