Git/GitLab/GitHub总结


git

gitlab(centos7)

在我看来,这三者的关系是,Git是钥匙,GitHub是公共场所,GitLab是自家房子。
GitLab
1.install gitlab

yum -y install policycoreutils openssh-server openssh-clients postfix
systemctl enable postfix && systemctl start postfix

centos 7系统的下载地址1:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
centos 7系统的下载地址2:https://packages.gitlab.com/gitlab/gitlab-ce

rpm -i gitlab-ce-11.6.1-ce.0.el7.x86_64.rpm
vim  /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
(gitlab-ctl restart)

2.SSH keys:

Settings->SSH keys->generate one看文档
cd ~/.shh
ls
cat ~/.ssh/id_rsa.pub

3.版本号

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
[260254@localhost 下载]$ rpm -qa|grep gitlab-ce-11.6.3-ce.0.el7.x86_64
gitlab-ce-11.6.3-ce.0.el7.x86_64
[260254@localhost 下载]$ rpm -q gitlab-ce-11.6.3-ce.0.el7.x86_64
gitlab-ce-11.6.3-ce.0.el7.x86_64
[260254@localhost 下载]$ rpm -q gitlab-ce-11.6.1-ce.0.el7.x86_64
未安装软件包 gitlab-ce-11.6.1-ce.0.el7.x86_64 
[260254@localhost 下载]$ rpm -e gitlab-ce-11.6.1-ce.0.el7.x86_64

在卸载gitlab然后再次安装执行sudo gitlab-ctl reconfigure的时候往往会出现:ruby_block[supervise_redis_sleep] action run,会一直卡无法往下进行!
解决方案:
1、按住CTRL+C强制结束;
2、sudo systemctl restart gitlab-runsvdir
3、sudo gitlab-ctl reconfigure
6.查看端口是否被占用

[260254@localhost ~]$ sudo lsof -i:8080

git(windows)

-----------------------20191215(win7下的git)-----------------------------------

git config --global user.name "kuochung"
git config --global user.email "jxgxzgc@163.com"
git clone [git xxxx]
git init  # git init --bare
git remote add origin [git xxxx]
git add .
git commit -m "first commit"
git push -u origin master

# ssh-key
cd .ssh
ssh-keygen -t rsa -C "jxgxzgc@163.com"  # 如果命令不存在 则where git 找到ssh-keygen的路径添加到用户环境变量中
more id_rsa.pub  # 用记事本或notepad打开复制粘贴到gitlab->Projects->Profile Settings->SSH Keys->Key里面


Git原理及操作简介

github(centos7)

-----------------------------------------------------20200305(github代码pull/push)----------------------------------

[260254@w26-260254 c3d-keras]$ git init
[260254@w26-260254 c3d-keras]$ ssh-keygen -t rsa -C "jxgxzgc@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/260254/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/260254/.ssh/id_rsa.
Your public key has been saved in /home/260254/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1JgTTa1RoABn9yhcrPZ8l8IG1LjSK1zYR28sPP0CcLY jxgxzgc@163.com
The key's randomart image is:
+---[RSA 2048]----+
|    ..+.+=o+.    |
|     + +=OB .    |
|      o*BBoB     |
|      =o*.E =    |
|     o =S= = o   |
|      o + = + .  |
|       . o o .   |
|                 |
|                 |
+----[SHA256]-----+
[260254@w26-260254 c3d-keras]$ cat ~/.ssh/id_rsa.pub
[260254@w26-260254 c3d-keras]$ ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Hi zhonguochong! You've successfully authenticated, but GitHub does not provide shell access.

git add
git commit -m "xxx"
git remote add origin https://github.com/zhonguochong/c3d_keras.git
git push -u origin master

git 版本管理(centos7)

版本回退:

git log --pretty=oneline
git reset --hard HEAD^^ #  git reset --hard HEAD~100 回退100个版本, HEAD是当前版本,也可以替换成版本号(commit ID)(是一个SHA1计算出来的一个非常大的数字,用十六进制表示)
git reflog --pretty=oneline
git reset --hard [commit ID]

管理修改:

git diff HEAD --[file]  # 查看file在工作区和版本库的区别

撤销修改:

git checkout [file]  # 从工作区撤销file的修改
git reset HEAD [file]  # 从暂存区撤销file的修改(这个时候在工作区的修改还需要用checkout来撤销)
git reset HEAD^  # 从版本库撤销file的修改(这个时候在暂存区的修改还需要用reset来撤销,再用checkout来撤销工作区的修改)

删除文件:

git add [file]
git commit -m 'add file'
# 这个时候你把工作区的文件file手动删除不要了  
git rm [file]
git commit -m 'remove file'  # 在工作区删除file,需要提交删除记录来更新版本库(同步到没有file)
# 如果你删除了还想要
git checkout --[file]
注意:从来没有被添加到版本库就被删除的文件,是无法恢复的!

添加远程库:

git remote add origin https://github.com/zhonguochong:xxx.git  # 添加仓库xxx.git, origin:远程库的名字,
git remote -v  # 查看连接的远程库
git push -u origin master  # -u是第一次关联master分支而用的,后续推送可以省略

从远程库克隆

git clone git@github.com:zhonguochong/xxx.git
git clone https://github.com/zhonguochong/xxx.git  # 速度要快

分支管理

在这里插入图片描述
在这里插入图片描述
创建分支并切换到新建的分支上:

git checkout -b dev  # 等价与git branch dev && git checkout dev or git switch -c dev

合并分支:

git checkout master  # 推荐使用git switch master(x)
git merge dev  # 把分支dev合并到master(使用的是Fast foward在删除dev分支后会丢失该分支所做的信息)(如果要保留dev分支的记录,则用:git merge --no-ff -m 'merge with no-ff' dev)
git branch -d dev  # 删除dev分支

当Git无法自动合并分支时,就必须首先解决冲突。解决冲突后,再提交,合并完成。

解决冲突就是把Git合并失败的文件手动编辑为我们希望的内容,再提交。

用git log --graph命令可以看到分支合并图

git log --graph --pretty=oneline --abbrev-commit

bug 分支

git checkout -b dev
git stash
git checkout master
git checkout -b issue-001
git add .
git cmomit -m 'bug fixed'  # remeber commit_id
git checkout master
git merge --no-ff -m 'merge bug fixed' issue-001
git branch -d issue-001
git log --graph --pretty=oneline --abbrev-commit
git checkout dev
git stash list
git stash apply stash@{x}
git stash drop
git cherry-pick <commit_id>  # 'bug fixed' commit_id

feature 分支

每开发一个功能需要建立一个feature分支

git checkout -b feature1
git checkout dev

这个时候正准备把feature1的功能模块合并到dev分支上,上面说不要这个功能模块了,这个时候需要:

git branch -D feature1

多人协作

git checkout -b dev  # 建立和远程仓库相应的开发分支
git branch --set-upstream-to=origin/dev dev  # push前需要先建立和远程分支的联系
git pull  # 当远程分支版本先于当地分支是,需要先pull更新之后再push
git push origin dev:dev  # 建立远程分支dev并对当地分支dev进行push

标签管理

git tag v1.0
git tag -a v0.1 -m 'xxx' <commit_id>
git tag
git show v0.1
git push --tags  #推送本地版本库所有的tags到远程仓库
git push origin v0.1  # 推送一个tag到远程仓库
git tag -d v0.9  #先在本地版本库删除tag
git push origin :refs/tags/v0.9  #再在远程仓库删除相应的tag

git submodule

git clone --recurse-submodules <main_project_url>  # 获取主项目和所有子项目源码
git submodule foreach ''## 它能在每一个子模块中运行任意命令
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值