开发者不管使用是什么语言,不可避免必须接触到GIT进行源代码的版本管理。
现在流行的开源网站很多比如 github,gitee这些,还可以自己搭建如 gitlab等等。不可避免需要各种命令,我收集和整理了一部分常用的,希望共享给各位看客。
安装GIT软件
http://gitforwindows.org/
https://github.com/git-for-windows/git/releases/tag/v2.16.1.windows.2
这里比较简单,安装时都默认一路下一步即可
通用命令指令
全局设置
git config --global user.name "你的姓名"
git config -- global user.email "你的邮箱"
创建本地新的存储库git init
git remote add origin http://git.dnngo.net/***.git
git clone http://git.dnngo.net/***.git
替换本地已经有的存储库git remote rename origin old-origin
git remote add origin http://git.dnngo.net/***.git
git push -u origin --all
git push -u origin --tags
提交你的项目到GITgit init
git remote add origin http://git.dnngo.net/***.git
git pull origin master
git add .
git commit -m "第一次提交"
git push origin master
当你第一次提交项目时,还应该修改 \.git\config 文件,在末尾加上[branch "master"]
remote = origin
merge = refs/heads/master
如果需要GIT回滚到特定版本,可如下操作:
先回滚,再强制提交
git reset --hard 297ff2dcf20605297684f296a4b4ccaa1cf4dc48
git push -f origin master
GITLAB 备份和恢复
如果你需要备份整个GIT,你需要执行以下命令gitlab-rake gitlab:backup:create
备份会创建在 /var/opt/gitlab/backups
这个目录
如果你要恢复,你可以执行以下步骤
进入备份的目录
cd /var/opt/gitlab/backups/
停止连接数据库的服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
查看gitlab版本
# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
12.3.5
修改权限
chmod 777 1555011412_2019_04_12_11.1.4_gitlab_backup.tar
恢复
gitlab-rake gitlab:backup:restore BACKUP=1555011412_2019_04_12_11.1.4
启动
gitlab-ctl start
检查是否可用
gitlab-rake gitlab:check SANITIZE=true
发表评论 取消回复