Git && Github学习笔记

Git && Github


一、本地库操作命令

本地初始化

git init
# 选择一个目录进入
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest
$ git init
Initialized empty Git repository in D:/DEVELOP/workspace/IntellijIdeaWorkspace/gittest/.git/

注意: .git 目录中存放的是本地库相关的子目录和文件, 不要删除, 也不要胡
乱修改。

设置签名(系统级用户)

git config --global user.name 用户名
git config --global user.email 邮箱
  • 访问范围为当前登录的操作系统的用户范围
  • 信息保存位置 ~/.gitconfig

设置签名(项目/仓库级用户)

git config user.name 用户名
git config user.email 邮箱
  • 仅在当前本地库范围内有效
  • 信息保存位置~/.gitconfig

状态查看

git status
  • 刚初始化仓库时
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
  • 刚添加文件还未将其加入暂存区时
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        good.txt

nothing added to commit but untracked files present (use "git add" to track)
  • 刚把文件通过git add添加到暂存区时
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   good.txt

  • 刚把文件通过git commit提交到本地库时
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git status
On branch master
nothing to commit, working tree clean

添加

git add
  • 添加文件到暂存区
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git add good.txt
warning: LF will be replaced by CRLF in good.txt.
The file will have its original line endings in your working directory
  • 可以通过git rm --cached 文件名的方式将其从暂存区删除
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git rm --cached good.txt
rm 'good.txt'

提交

git commit
  • 将暂存区的内容提交到本地库
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git commit good.txt
warning: LF will be replaced by CRLF in good.txt.
The file will have its original line endings in your working directory
[master (root-commit) 1f179a5] my first commit
 1 file changed, 1 insertion(+)
 create mode 100644 good.txt
git commit -m “提交说明” 文件名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git commit -m "my second commit" good.txt
warning: LF will be replaced by CRLF in good.txt.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in good.txt.
The file will have its original line endings in your working directory
[master 175df83] my second commit
 1 file changed, 1 insertion(+), 1 deletion(-)

查看历史记录

git log
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git log
commit 42749fa32da8f214b3e4b8fa11999c71051ee714 (HEAD -> master)
Author: helin9s <1024633414@qq.com>
Date:   Sun Jan 19 22:49:44 2020 +0800

    my third commit

commit 175df83e9e632783d071de955f8b2f3acb6957a0
Author: helin9s <1024633414@qq.com>
Date:   Sun Jan 19 22:46:26 2020 +0800

    my second commit

commit 1f179a57c3abcdf3e1980d7d1fe14642196485b5
Author: helin9s <1024633414@qq.com>
Date:   Sun Jan 19 22:39:36 2020 +0800

    my first commit


  • 多屏显示控制方式:
  • 空格向下翻页
  • b 向上翻页
  • q 退出
git log --pretty=oneline
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git log --pretty=oneline
42749fa32da8f214b3e4b8fa11999c71051ee714 (HEAD -> master) my third commit
175df83e9e632783d071de955f8b2f3acb6957a0 my second commit
1f179a57c3abcdf3e1980d7d1fe14642196485b5 my first commit


git log --oneline
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git log --oneline
42749fa (HEAD -> master) my third commit
175df83 my second commit
1f179a5 my first commit

git refolg
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reflog
42749fa (HEAD -> master) HEAD@{0}: commit: my third commit
175df83 HEAD@{1}: commit: my second commit
1f179a5 HEAD@{2}: commit (initial): my first commit

HEAD@{移动到当前版本需要多少步}

版本前进后退

git reset --hard 索引值
# 改变之前
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reflog
42749fa (HEAD -> master) HEAD@{0}: commit: my third commit
175df83 HEAD@{1}: commit: my second commit
1f179a5 HEAD@{2}: commit (initial): my first commit

# 版本后退
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reset --hard 1f179a5
HEAD is now at 1f179a5 my first commit

# 查看版本
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reflog
1f179a5 (HEAD -> master) HEAD@{0}: reset: moving to 1f179a5
42749fa HEAD@{1}: commit: my third commit
175df83 HEAD@{2}: commit: my second commit
1f179a5 (HEAD -> master) HEAD@{3}: commit (initial): my first commit

# 版本前进同理
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reset --hard 42749fa
HEAD is now at 42749fa my third commit

# 查看版本
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git reflog
42749fa (HEAD -> master) HEAD@{0}: reset: moving to 42749fa
1f179a5 HEAD@{1}: reset: moving to 1f179a5
42749fa (HEAD -> master) HEAD@{2}: commit: my third commit
175df83 HEAD@{3}: commit: my second commit
1f179a5 HEAD@{4}: commit (initial): my first commit


  • reset 命令的三个参数对比
    1. –soft:仅仅在本地库移动HEAD指针
    2. –mixed:在本地库移动HEAD指针,重置暂存区
    3. –hard:在本地库移动HEAD指针,重置暂存区,重置工作区

删除文件找回

git reset --hard 指针位置
  • 删除操作已经提交到本地库,指针位置指向历史记录(历史版本索引)
  • 删除操作尚未提交到本地库,指针位置使用HEAD

比较文件差异

git diff 文件名
  • 将工作区中的文件和暂存区进行比较
git diff 本地库历史版本 文件名
  • 将工作区中的文件和本地库历史记录比较
git diff
  • 不带文件名比较多个文件
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git diff 42749fa good.txt
diff --git a/good.txt b/good.txt
index e9305b3..d200834 100644
--- a/good.txt
+++ b/good.txt
@@ -1,5 +1 @@
 aaaaaaaaaaaaa
-bbbbbbbbbbb
-cccccc
-dddddd
-

二、分支管理

创建分支

git branch 分支名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch hot_fix

查看分支

git branch
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch
  hot_fix
* master

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch -v	#查看分支并显示最新的修改
  hot_fix 175df83 my second commit
* master    175df83 my second commit


删除分支

git branch -d 分支名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch -a
  hotot_fix
* master
  rm

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch -d rm
Deleted branch rm (was a520ad8).

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git branch
  hotot_fix
* master


切换分支

git checkout 分支名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git checkout hot_fix
Switched to branch 'hot_fix'

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)
$ git branch
* hot_fix
  master

合并分支

git merge 有新内容的分支名
# 第一步,先要切换到接受修改的分支(需要增加新内容的分支)上
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)
$ git checkout master
Switched to branch 'master'

# 第二步,执行merge命令,合并有新内容的分支
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git merge hot_fix
Updating 175df83..e8876e9
Fast-forward
 apple.txt | 2 ++
 good.txt  | 1 +
 2 files changed, 3 insertions(+)
 create mode 100644 apple.txt

解决冲突

# 修改master分支下的good文件并提交
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ vim good.txt

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git commit -m "master commit" good.txt
[master 82d773d] master commit
 1 file changed, 1 insertion(+), 1 deletion(-)

# 切换到hot_fix分支并修改good文件的同样位置
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git checkout hot_fix
Switched to branch 'hot_fix'

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)
$ vim good.txt

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)
$ git commit -m "hot_fix commit" good.txt
[hotot_fix a520ad8] hot_fix commit
 1 file changed, 3 insertions(+), 1 deletion(-)

# 重新切换成master分支,执行合并,出现冲突
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)
$ git checkout master
Switched to branch 'master'

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git merge hot_fix
Auto-merging good.txt
CONFLICT (content): Merge conflict in good.txt
Automatic merge failed; fix conflicts and then commit the result.

  • 解决冲突
# 编辑冲突文件
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)
$ vim good.txt
  • 处理冲突
aaaaaaaaaaaaa
<<<<<<< HEAD		# <<<< HEAD到=====之间是当前分支的内容
bbbb   ccccc
=======
bbbb dddd			#======到>>>>>>> hot_fix之间是hot_fix分支的内容

dddd
>>>>>>> hot_fix

  • 提交合并
# 编辑完成后查看当前文件状态,显示还有冲突
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)
$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   good.txt

no changes added to commit (use "git add" and/or "git commit -a")

# 把修改提交到暂存区后标记为合并,但是尚未提交
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)
$ git add good.txt

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)
$ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

        modified:   good.txt

# commit完成真正的合并,此处不能加文件名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)
$ git commit -m "resolve confilct"
[master 3d38ffc] resolve confilct

三、远程仓库操作

查看远程仓库

git remote -v
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote -v

git绑定远程仓库地址

git remote add 仓库别名 仓库地址
# github  origin是仓库地址的别名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote add origin https://github.com/helin9s/gittest.git

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote -v
origin  https://github.com/helin9s/gittest.git (fetch)
origin  https://github.com/helin9s/gittest.git (push)

# gitee
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote add gitee https://gitee.com/helin9S/gittest.git

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote -v
gitee   https://gitee.com/helin9S/gittest.git (fetch)
gitee   https://gitee.com/helin9S/gittest.git (push)

git删除绑定的远程仓库地址

git remote rm 仓库别名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git remote rm origin

git 推送本地分支到远程仓库

git push 仓库别名 分支名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git push origin master
# 需要输入github或gitee的账号密码
To https://github.com/helin9s/gittest.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/helin9s/gittest.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

  • 因为创建仓库时生成了readme.md文件
git push -u 仓库别名 分支名 -f
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ git push -u origin master -f
# 强制推送,推送成功
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 12 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (21/21), 1.63 KiB | 556.00 KiB/s, done.
Total 21 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/helin9s/gittest.git
 + bd9372f...3d38ffc master -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'origin'.
  • 注意:git本身不能保存账号密码,账号密码是通过window的控制面板\所有控制面板项\凭据管理器进行保存的

git克隆远程仓库到本地

git clone 远程仓库地址

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone
$ git clone https://gitee.com/helin9S/gittest.git
Cloning into 'gittest'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 21 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (21/21), done.
  • 完整的把远程仓库下载到本地
  • 创建origin远程地址别名
  • 初始化本地库

git拉取远程仓库的修改

git pull 远程仓库别名 远程分支名
  • pull=fetch+merge
git fetch 远程仓库别名 远程分支名
  • 下载远程仓库的文件,并不改变本地工作区的文件
git merge 远程仓库别名/远程分支名
  • 合并

SSH登陆

1. 创建密钥
# 进入home目录
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)
$ cd ~
# 删除以前的ssh密钥
helin9s@LAPTOP-M719A9K6 MINGW64 ~
$ rm -r .ssh/
rm: cannot remove '.ssh/': No such file or directory
# 生成密钥,需要确认的地方全部回车使用默认,注意,`-C`的C是大写
helin9s@LAPTOP-M719A9K6 MINGW64 ~
$ ssh-keygen -t rsa -C helin9s@163.com
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/helin9s/.ssh/id_rsa):
Created directory '/c/Users/helin9s/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/helin9s/.ssh/id_rsa.
Your public key has been saved in /c/Users/helin9s/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4IW6qG1YqktEEbTsGFNyxIS6UizDOlG57sQywlan/CA helin9s@163.com
The key's randomart image is:
+---[RSA 3072]----+
|oO*.             |
|o+*    .         |
|=* .  o .        |
|O++. + o         |
|+@o + . S        |
|XE== .           |
|+@o +            |
|+oo  .           |
|=o.              |
+----[SHA256]-----+

2. 把密钥保存到远程仓库
# 进入.ssh目录
helin9s@LAPTOP-M719A9K6 MINGW64 ~
$ cd .ssh/

helin9s@LAPTOP-M719A9K6 MINGW64 ~/.ssh
$ ll
total 5
-rw-r--r-- 1 helin9s 197121 2602  1月 21 16:14 id_rsa
-rw-r--r-- 1 helin9s 197121  569  1月 21 16:14 id_rsa.pub
# 查看id_rsa.pub文件,全部复制
helin9s@LAPTOP-M719A9K6 MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCvnfCr+dxqqo1qGEz4Gt7lTrR9zf26QLXRwwY9LdBi8QIaBend45RfdlZ6mZF6GsSz2IY2JSI1Te7OO6QXJDFCiEz37uJn+31xZ7/vPjyzZSydSmnGlNm0/dCm2P/n0E+xHZ9mCK1vSoNjdRbVYgRcTHpwYLGfR4Y1y5Y3TJrWFyBSzZDiFQZXDNyUv1puRB5cb0LY1fOm8UpQb9utdl4Gk7pPKbYGdFnc0EF5YKaouhEJeQD+3qNTH58UlAFVWWtyu6ZUgvZBBWB1M6Di+4LNNBW6ndfR6WrXrdoraO1lvSQNxaVWgxBkpxSvQtmmCisanhjisK79EJSuhppkYJEARzH0gdHNZI7lCvziwjWOEqhLIWm7/eMxh2rBPppxwVEAc+7Y5UvtAUJSDI1T8ttt17kYKr89EWLzMyUAWPlkpKf4FVMvOXO1DRgnFYpU9H/gIrXFD1kXOy6SeBXnpo8TToa6czC94R2te28MIVb3DKKpqT2+xX0GsxxDuwu73OM= helin9s@163.com

3. 打开github或者gitee
  • 如果是githubsettings->SSH keys->new ssh key,然后把上面复制的密钥全部粘贴保存

  • 如果是gitee设置->SSH公钥,然后把上面复制的密钥全部粘贴保存

4. git客户端访问
# 查看原来的http仓库
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ git remote -v
origin  https://gitee.com/helin9S/gittest.git (fetch)
origin  https://gitee.com/helin9S/gittest.git (push)
# 添加新的ssh仓库
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ git remote add origin_ssh git@gitee.com:helin9S/gittest.git

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ git remote -v
origin  https://gitee.com/helin9S/gittest.git (fetch)
origin  https://gitee.com/helin9S/gittest.git (push)
origin_ssh      git@gitee.com:helin9S/gittest.git (fetch)
origin_ssh      git@gitee.com:helin9S/gittest.git (push)

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ ll
total 2
-rw-r--r-- 1 helin9s 197121 14  1月 21 00:28 apple.txt
-rw-r--r-- 1 helin9s 197121 46  1月 21 00:28 good.txt
# 修改文件并提交到本地库
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ vim apple.txt

helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ git commit -m "apple pen commit" apple.txt
[master 7e17771] apple pen commit
 1 file changed, 1 insertion(+)
# 推送修改到ssh远程仓库
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)
$ git push origin_ssh master
The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes #输入yes确认
Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 279 bytes | 279.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To gitee.com:helin9S/gittest.git
   3d38ffc..7e17771  master -> master

四、git 工作流

概念

​ 在项目开发过程中使用 Git 的方式

分类

1. 集中式工作流

​ 像 SVN 一样, 集中式工作流以中央仓库作为项目所有修改的单点实体。 所有
修改都提交到 Master 这个分支上。
这种方式与 SVN 的主要区别就是开发人员有本地库。Git 很多特性并没有用到。

2. GitFlow 工作流

​ Gitflow 工作流通过为功能开发、 发布准备和维护设立了独立的分支, 让发布
迭代过程更流畅。 严格的分支模型也为大型项目提供了一些非常必要的结构.

3. Forking 工作流

​ Forking 工作流是在 GitFlow 基础上, 充分利用了 Git 的 Fork 和 pull request 的
功能以达到代码审核的目的。 更适合安全可靠地管理大团队的开发者, 而且能接受
不信任贡献者的提交。

五、Gitlab 服务器搭建过程

官网地址

​ 首页: https://about.gitlab.com/
​ 安装说明: https://about.gitlab.com/installation/

安装、配置、访问

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee

# 初始化配置 gitlab
gitlab-ctl reconfigure
# 启动 gitlab 服务
gitlab-ctl start
# 停止 gitlab 服务
gitlab-ctl stop
# 通过ip进行访问
http://服务器ip
  • 设置域名访问
# 修改配置文件
$ vim /etc/gitlab/gitlab.rb 
………………
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
# external_url 'http://gitlab.example.com'
# 能够解析
external_url 'http://gitlab.helin9s.cn'

#配置启动
$ gitlab-ctl reconfigure

GitLab常用命令

gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop        # 停止所有 gitlab 组件;
gitlab-ctl restart        # 重启所有 gitlab 组件;
gitlab-ctl status        # 查看服务状态;
gitlab-ctl reconfigure        # 启动服务;
vim /etc/gitlab/gitlab.rb        # 修改默认的配置文件;
gitlab-ctl tail        # 查看日志;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;

GitLab卸载

# 停止gitlab
[root@localhost ~]$ gitlab-ctl stop
# 查看gitlab进程
[root@localhost ~]$ ps -aux|grep gitlab
# 如果有进程则杀掉
[root@localhost ~]$ ps -9 gitlab的PID
# 卸载gitlab
[root@localhost ~]$ rpm -e gitlab-ee
# 删除gitlab的所有文件
[root@localhost ~]$ find / -name gitlab|xargs rm -rf
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值