git-gitlab操作指南

272 阅读1分钟

1.git版本回退

1)先找到要回退的日期,打上tag标识

这个一大串的码 就是要回退到的版本

2)切换到主干上(或者是要回退的分支上)

git checkout master

使用git tag 查看标签

如:t1

查看你要回退的标签的commit码 git show t1

git show t1
commit 9e9f193295ec00fec5c4c61c730a5c430556ddc5 (tag: t1)
Merge: d1d16bc 3990499
Author: <E8><83><A1><E6><99><93><E5><BD><AC> <huxiaobin@knet.cn>
Date:   Mon Apr 13 10:14:14 2020 +0800
<E5><90><88><E5><B9><B6><E5><88><86><E6><94><AF> '200309' <E5><88><B0> 'master'

3)强制回退到t1

通过commit id回退
git reset --hard 3990499a32a11f32ec86f4f0afb547d001b6e854
HEAD is now at 3990499 初始化
​
git push -f origin master 
Total 0 (delta 0), reused 0 (delta 0)
To http://xx/wz/knet-domain-orm.git
 + 9e9f193...3990499 master -> master (forced update)
​
​

如果出现:

git push -f origin master 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://XX/wz/knet-domain-orm.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'http://XX/wz/knet-domain-orm.git'

You are not allowed to force push code to a protected branch on this project.表示此分支是受保护的,

可以使用设置-》仓库 改变保护

再次执行 git push -f origin master 就可以