将已经存在的项目迁移到新的服务器:
1、将项目从原先地址克隆,保证是最新代码
2、在新地址的服务器上面创建新的项目
3、代码备份:执行cp -R 最新代码项目名称 生成的copy备份文件项目名称 cp -R oldname newname
4、git remote remove origin 断开和原来远程的连接
5、gp: git push 提交分支到远程 具体git 命令简写可参照:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git
新项目提交到服务器:
1、git上面创建项目
2、cd 进入本地项目
3、git init 初始化项目
4、git remote add origin git@gitlab.mondora.cn:front/szkj-iOS.git
5、git add .
6、git commit
7、git push -u origin master
代码回滚:
git log 查看提交的commit hash,找到要回滚的hash
git reset --hard commitHash 回滚到需要的版本
git push -f origin master
此时如果操作的是master分支,可能会报错:
remote: GitLab: You are not allowed to force push code to a protected branch on this project
原因是master分支默认被保护,在图中位置找到Protected Branches设置为
Unprotected即可

网友评论