美文网首页
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回退

    开发的时候经常会遇到 代码要回退的时候 每次都要百度一下 现在写下这片文章作为记录 1.先查看提交历史 git l...

  • 【git】日常操作

    回滚代码到某个commit 先git log,查看commit ID 回退命令: GIT或Gitlab修改密码之后...

  • Git几种回退方式

    第一种回退:本地库回退到上一次commit 第二种回退:本地库回退到指定commit 第三种回退:远程库回退

  • git如何回滚到某一个分支

    1. 查看所需回退的版本 拿到你想要回退版本的commit_id 2.如何回退 回退之后,将回退的版本推送到远程分...

  • Git 回滚代码到某个 commit

    1、回退命令: 回退到上个版本git reset --hard HEAD^ 回退到前2次提交之前,以此类推,回退到...

  • 监听浏览器回退事件

    监听回退事件,指定回退的页面

  • git 终端命令

    git本地分支回退: git远程分支回退:

  • iOS webView 回退栈

    Android 的webView有回退栈,其实iOS的webView也有回退栈! webView的回退栈其实就是表...

  • Git应该记住的点

    一、回退 1.本地回退(未add) git checkout . 2.暂存区回退(已add,未commit...

  • gitlab点击项目 报500错误解决方案

    gitlab issueshttps://gitlab.com/gitlab-org/gitlab-foss/-/...

网友评论

      本文标题:gitLab回退

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