美文网首页
gitLab回退

gitLab回退

作者: Gumball_a45f | 来源:发表于2021-05-08 09:28 被阅读0次

    开发的时候经常会遇到 代码要回退的时候 每次都要百度一下 现在写下这片文章作为记录

    1.先查看提交历史 git log

    2.回退到指定版本git reset xxx

    3.回退上一个版本git reset HEAD^

    4.回退到和远程的一样git reset –hard origin/master

    5.回退到某个指定版本,回退前所有的修改丢掉git reset --hard eb33(我常用的)

    已经提交到gitlab如何同步回退gitlab的代码
    1、git本地回退到指定版本后,按以往的提交顺序进行提交时会出现这个问题

    $ git push origin master
    Username for 'http://172.16.15.19': lbp
    To http://172.16.15.19/cop2/cop_task.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'http://172.16.15.19/cop2/cop_task.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    2、这是因为gitlab已经在你提交历史前面了,你无法把push过的再次push进行覆盖,这个时候加个参数–force就行

    $ git push origin master --force
    Username for 'http://172.16.15.19': lbp
    Total 0 (delta 0), reused 0 (delta 0)
    remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    To http://172.16.15.19/cop2/cop_task.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'http://172.16.15.19/cop2/cop_task.git'
    

    3、加完参数后发现gitlab不允许强行push到保护的分支上,解决方法是让项目的管理员暂时在gitlab上把你要提交的分支设置为不受保护的分支即可

    $ git push origin master --force
    Username for 'http://172.16.15.19': lbp
    Total 0 (delta 0), reused 0 (delta 0)
    To http://172.16.15.19/cop2/cop_task.git
     + b69a4ce...eb3378a master -> master (forced update)
    

    相关文章

      网友评论

          本文标题:gitLab回退

          本文链接:https://www.haomeiwen.com/subject/mwhedltx.html