Git && Github
一、本地库操作命令
本地初始化
git init
# 选择一个目录进入helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest$ git initInitialized 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 statusOn branch masterNo commits yetnothing to commit (create/copy files and use "git add" to track)
刚添加文件还未将其加入暂存区时
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git statusOn branch masterNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)good.txtnothing 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 statusOn branch masterNo commits yetChanges 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 statusOn branch masternothing to commit, working tree clean
添加
git add
添加文件到暂存区helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git add good.txtwarning: 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.txtrm 'good.txt'
提交
git commit
将暂存区的内容提交到本地库helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git commit good.txtwarning: 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 commit1 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.txtwarning: LF will be replaced by CRLF in good.txt.The file will have its original line endings in your working directorywarning: 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 commit1 file changed, 1 insertion(+), 1 deletion(-)
查看历史记录
git log
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git logcommit 42749fa32da8f214b3e4b8fa11999c71051ee714 (HEAD -> master)Author: helin9s <1024633414@>Date: Sun Jan 19 22:49:44 +0800my third commitcommit 175df83e9e632783d071de955f8b2f3acb6957a0Author: helin9s <1024633414@>Date: Sun Jan 19 22:46:26 +0800my second commitcommit 1f179a57c3abcdf3e1980d7d1fe14642196485b5Author: helin9s <1024633414@>Date: Sun Jan 19 22:39:36 +0800my first commit
多屏显示控制方式:
空格向下翻页b 向上翻页q 退出
git log --pretty=oneline
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git log --pretty=oneline42749fa32da8f214b3e4b8fa11999c71051ee714 (HEAD -> master) my third commit175df83e9e632783d071de955f8b2f3acb6957a0 my second commit1f179a57c3abcdf3e1980d7d1fe14642196485b5 my first commit
git log --oneline
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git log --oneline42749fa (HEAD -> master) my third commit175df83 my second commit1f179a5 my first commit
git refolg
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reflog42749fa (HEAD -> master) HEAD@{0}: commit: my third commit175df83 HEAD@{1}: commit: my second commit1f179a5 HEAD@{2}: commit (initial): my first commit
HEAD@{移动到当前版本需要多少步}
版本前进后退
git reset --hard 索引值
# 改变之前helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reflog42749fa (HEAD -> master) HEAD@{0}: commit: my third commit175df83 HEAD@{1}: commit: my second commit1f179a5 HEAD@{2}: commit (initial): my first commit# 版本后退helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reset --hard 1f179a5HEAD is now at 1f179a5 my first commit# 查看版本helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reflog1f179a5 (HEAD -> master) HEAD@{0}: reset: moving to 1f179a542749fa HEAD@{1}: commit: my third commit175df83 HEAD@{2}: commit: my second commit1f179a5 (HEAD -> master) HEAD@{3}: commit (initial): my first commit# 版本前进同理helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reset --hard 42749faHEAD is now at 42749fa my third commit# 查看版本helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git reflog42749fa (HEAD -> master) HEAD@{0}: reset: moving to 42749fa1f179a5 HEAD@{1}: reset: moving to 1f179a542749fa (HEAD -> master) HEAD@{2}: commit: my third commit175df83 HEAD@{3}: commit: my second commit1f179a5 HEAD@{4}: commit (initial): my first commit
reset 命令的三个参数对比–soft:仅仅在本地库移动HEAD指针–mixed:在本地库移动HEAD指针,重置暂存区–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.txtdiff --git a/good.txt b/good.txtindex e9305b3..d34 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 branchhot_fix* masterhelin9s@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 -ahotot_fix* masterrmhelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git branch -d rmDeleted branch rm (was a520ad8).helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git branchhotot_fix* master
切换分支
git checkout 分支名
helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git checkout hot_fixSwitched to branch 'hot_fix'helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)$ git branch* hot_fixmaster
合并分支
git merge 有新内容的分支名
# 第一步,先要切换到接受修改的分支(需要增加新内容的分支)上helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)$ git checkout masterSwitched to branch 'master'# 第二步,执行merge命令,合并有新内容的分支helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git merge hot_fixUpdating 175df83..e8876e9Fast-forwardapple.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.txthelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git commit -m "master commit" good.txt[master 82d773d] master commit1 file changed, 1 insertion(+), 1 deletion(-)# 切换到hot_fix分支并修改good文件的同样位置helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git checkout hot_fixSwitched to branch 'hot_fix'helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)$ vim good.txthelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)$ git commit -m "hot_fix commit" good.txt[hotot_fix a520ad8] hot_fix commit1 file changed, 3 insertions(+), 1 deletion(-)# 重新切换成master分支,执行合并,出现冲突helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (hot_fix)$ git checkout masterSwitched to branch 'master'helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git merge hot_fixAuto-merging good.txtCONFLICT (content): Merge conflict in good.txtAutomatic 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 statusOn branch masterYou 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.txtno 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.txthelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master|MERGING)$ git statusOn branch masterAll 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 /helin9s/gittest.githelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git remote -vorigin /helin9s/gittest.git (fetch)origin /helin9s/gittest.git (push)# giteehelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git remote add gitee /helin9S/gittest.githelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gittest (master)$ git remote -vgitee /helin9S/gittest.git (fetch)gitee /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 /helin9s/gittest.git! [rejected] master -> master (fetch first)error: failed to push some refs to '/helin9s/gittest.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (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 threadsCompressing 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 /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 /helin9S/gittest.gitCloning 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+mergegit 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@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@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$ lltotal 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.pubssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCvnfCr+dxqqo1qGEz4Gt7lTrR9zf26QLXRwwY9LdBi8QIaBend45RfdlZ6mZF6GsSz2IY2JSI1Te7OO6QXJDFCiEz37uJn+31xZ7/vPjyzZSydSmnGlNm0/dCm2P/n0E+xHZ9mCK1vSoNjdRbVYgRcTHpwYLGfR4Y1y5Y3TJrWFyBSzZDiFQZXDNyUv1puRB5cb0LY1fOm8UpQb9utdl4Gk7pPKbYGdFnc0EF5YKaouhEJeQD+3qNTH58UlAFVWWtyu6ZUgvZBBWB1M6Di+4LNNBW6ndfR6WrXrdoraO1lvSQNxaVWgxBkpxSvQtmmCisanhjisK79EJSuhppkYJEARzH0gdHNZI7lCvziwjWOEqhLIWm7/eMxh2rBPppxwVEAc+7Y5UvtAUJSDI1T8ttt17kYKr89EWLzMyUAWPlkpKf4FVMvOXO1DRgnFYpU9H/gIrXFD1kXOy6SeBXnpo8TToa6czC94R2te28MIVb3DKKpqT2+xX0GsxxDuwu73OM= helin9s@
3. 打开github
或者gitee
如果是github,settings->SSH keys->new ssh key
,然后把上面复制的密钥全部粘贴保存
如果是gitee,设置->SSH公钥
,然后把上面复制的密钥全部粘贴保存
4. git客户端访问
# 查看原来的http仓库helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ git remote -vorigin /helin9S/gittest.git (fetch)origin /helin9S/gittest.git (push)# 添加新的ssh仓库helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ git remote add origin_ssh git@:helin9S/gittest.githelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ git remote -vorigin /helin9S/gittest.git (fetch)origin /helin9S/gittest.git (push)origin_sshgit@:helin9S/gittest.git (fetch)origin_sshgit@:helin9S/gittest.git (push)helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ lltotal 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.txthelin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ git commit -m "apple pen commit" apple.txt[master 7e17771] apple pen commit1 file changed, 1 insertion(+)# 推送修改到ssh远程仓库helin9s@LAPTOP-M719A9K6 MINGW64 /d/DEVELOP/workspace/IntellijIdeaWorkspace/gitclone/gittest (master)$ git push origin_ssh masterThe authenticity of host ' (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 ',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 threadsCompressing 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 [GNK-3.8]To :helin9S/gittest.git3d38ffc..7e17771 master -> master
四、git 工作流
概念
在项目开发过程中使用 Git 的方式
分类
1. 集中式工作流
像 SVN 一样, 集中式工作流以中央仓库作为项目所有修改的单点实体。 所有
修改都提交到 Master 这个分支上。
这种方式与 SVN 的主要区别就是开发人员有本地库。Git 很多特性并没有用到。
2. GitFlow 工作流
Gitflow 工作流通过为功能开发、 发布准备和维护设立了独立的分支, 让发布
迭代过程更流畅。 严格的分支模型也为大型项目提供了一些非常必要的结构.
3. Forking 工作流
Forking 工作流是在 GitFlow 基础上, 充分利用了 Git 的 Fork 和 pull request 的
功能以达到代码审核的目的。 更适合安全可靠地管理大团队的开发者, 而且能接受
不信任贡献者的提交。
五、Gitlab 服务器搭建过程
官网地址
首页: /
安装说明: /installation/
安装、配置、访问
sudo yum install -y curl policycoreutils-python openssh-serversudo systemctl enable sshdsudo systemctl start sshdsudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --permanent --add-service=httpssudo systemctl reload firewalldsudo yum install postfixsudo systemctl enable postfixsudo systemctl start postfixcurl /install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bashsudo EXTERNAL_URL="" yum install -y gitlab-ee# 初始化配置 gitlabgitlab-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:##! /omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab# external_url ''# 能够解析external_url ''#配置启动$ 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
如果觉得《Git Github学习笔记》对你有帮助,请点赞、收藏,并留下你的观点哦!