天天看點

Git/GitLab/GitHub總結gitlab(centos7)git(windows)github(centos7)git 版本管理(centos7)

目錄

  • gitlab(centos7)
  • git(windows)
  • github(centos7)
  • git 版本管理(centos7)
    • 分支管理
    • bug 分支
    • feature 分支
    • 多人協作
    • 标簽管理
Git/GitLab/GitHub總結gitlab(centos7)git(windows)github(centos7)git 版本管理(centos7)

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
           
[[email protected] 下載下傳]$ rpm -qa|grep gitlab-ce-11.6.3-ce.0.el7.x86_64
gitlab-ce-11.6.3-ce.0.el7.x86_64
[[email protected] 下載下傳]$ rpm -q gitlab-ce-11.6.3-ce.0.el7.x86_64
gitlab-ce-11.6.3-ce.0.el7.x86_64
[[email protected] 下載下傳]$ rpm -q gitlab-ce-11.6.1-ce.0.el7.x86_64
未安裝軟體包 gitlab-ce-11.6.1-ce.0.el7.x86_64 
[[email protected] 下載下傳]$ 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.檢視端口是否被占用

[[email protected] ~]$ sudo lsof -i:8080
           

git(windows)

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

git config --global user.name "kuochung"
git config --global user.email "[email protected]"
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 "[email protected]"  # 如果指令不存在 則where git 找到ssh-keygen的路徑添加到使用者環境變量中
more id_rsa.pub  # 用記事本或notepad打開複制粘貼到gitlab->Projects->Profile Settings->SSH Keys->Key裡面


           

Git原理及操作簡介

github(centos7)

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

[[email protected] c3d-keras]$ git init
[[email protected] c3d-keras]$ ssh-keygen -t rsa -C "[email protected]"
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 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    ..+.+=o+.    |
|     + +=OB .    |
|      o*BBoB     |
|      =o*.E =    |
|     o =S= = o   |
|      o + = + .  |
|       . o o .   |
|                 |
|                 |
+----[SHA256]-----+
[[email protected] c3d-keras]$ cat ~/.ssh/id_rsa.pub
[[email protected] c3d-keras]$ ssh -T [email protected]
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 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 [email protected]:zhonguochong/xxx.git
git clone https://github.com/zhonguochong/xxx.git  # 速度要快
           

分支管理

Git/GitLab/GitHub總結gitlab(centos7)git(windows)github(centos7)git 版本管理(centos7)
Git/GitLab/GitHub總結gitlab(centos7)git(windows)github(centos7)git 版本管理(centos7)

建立分支并切換到建立的分支上:

合并分支:

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