Git集成Gitlab,Github,Gitee
<center><h1>Git</h1></center><h2 id="一git概述">一、Git概述</h2>
<p>Git大家都听过,是一个免费的、开源的分布式控制系统。</p>
<h3 id="1-版本控制工具">1. 版本控制工具</h3>
<p>版本控制工具分类两类:集中式版本控制工具和分布式版本控制工具</p>
<ul>
<li>
<p><strong>集中式版本控制工具</strong></p>
<p>例如SVN、CVS等工具,都包含一个单一的集中管理的服务器,保存了所有文件的修订版本。协同工作的人们通过客户端连接到服务器,取出最新的文件并同步更新。</p>
<p><strong>优点:</strong></p>
<ul>
<li>每个人都可以在一定程度上看到项目中的其他人正在做些什 么。</li>
<li>管理员也可以轻松掌控每个开发者的权限</li>
<li>管理一个集中化的版本控制系统</li>
</ul>
<p><strong>缺点:</strong>服务器宕机,就无法协同工作。</p>
</li>
<li>
<p><strong>分布式版本控制工具</strong></p>
<p>例如Git等工具, 服务端保存了最新版本的代码,客户端想协同工作首先要将代码仓库完整地镜像下来,并可以在本地进行版本管理并同步更新。</p>
<p>优点:</p>
<ul>
<li>服务器断网的情况下也可以进行开发(因为版本控制是在本地进行的)</li>
<li>每个客户端保存的也都是整个完整的项目(包含历史记录,更加安全)</li>
</ul>
</li>
</ul>
<h3 id="2-git机制">2. Git机制</h3>
<p>工作代码→通过添加add,到暂存区,可以修改→通过提交commit,存储到本地库,无法更改</p>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222416648-2016186174.png" alt="image-20220601164956025" style="zoom: 67%">
<h3 id="3-git和代码托管中心">3. Git和代码托管中心</h3>
<p>代码托管中心,即远程库是基于网络服务器的远程代码仓库。主要分为两类:</p>
<ul>
<li>基于局域网:GitLab</li>
<li>基于互联网:
<ul>
<li>GitHub</li>
<li>Gitee</li>
</ul>
</li>
</ul>
<h2 id="二git安装">二、Git安装</h2>
<p>官网地址: https://git-scm.com/</p>
<p><strong>安装:</strong></p>
<p>双击Git-2.31.1-64-bit.exe</p>
<p>→ 同意协议</p>
<p>→ 配置安装位置(非中文,不包含空格目录)</p>
<p>→ 选择Git配置</p>
<p>→ 确认Git安装目录名称 → 选择Git默认编辑器</p>
<p>→ 选择默认分支名设置</p>
<p>→ 是否修改Git环境变量</p>
<p>→ 选择客户端联机协议OpenSSL</p>
<p>→配置Git 文件的行换行符,选择第一个自动转换(Windows 使用 CRLF,Linux 使用 LF)</p>
<p>→ 选择 Git 终端类型,选择默认的 Git Bash 终端</p>
<p>→选择 pull 合并的模式,选择默认fast-forward or merge</p>
<p>→选择 Git 的凭据管理器, 保存登录状态</p>
<p>→其他配置</p>
<p>→选择实验室功能,技术还不成熟,有已知的 bug,不要勾选,然后点击右下角的 Install 按钮,开始安装 Git</p>
<p>安装成功,打开Git Bash,输入<code>Git --version</code>查看Git版本信息。</p>
<h2 id="三git常用命令">三、Git常用命令</h2>
<p><strong>常用命令</strong></p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git config --global user.name 用户名</td>
<td>设置用户签名</td>
</tr>
<tr>
<td>git config --global user.email 邮箱</td>
<td>设置用户邮箱</td>
</tr>
<tr>
<td>git init</td>
<td>初始化本地库</td>
</tr>
<tr>
<td>git status</td>
<td>查看本地库状态</td>
</tr>
<tr>
<td>git add 文件名</td>
<td>添加到暂存区</td>
</tr>
<tr>
<td>git commit -m "日志信息" 文件名</td>
<td>提交到本地库</td>
</tr>
<tr>
<td>git reflog</td>
<td>查看历史记录</td>
</tr>
<tr>
<td>git reset --hard 版本号</td>
<td>版本穿梭</td>
</tr>
</tbody>
</table>
<h3 id="1-设置用户签名">1. 设置用户签名</h3>
<pre><code class="language-shell">$ git config --global user.name Vicstal
$ git config --global user.email 2428991957@qq.com
$ cat ~/.gitconfig
name = Vicstal
email = 2428991957@qq.com
</code></pre>
<p>Git 首次安装必须设置一下用户签名,否则无法提交代码。</p>
<p>并且这里设置用户签名和将来登录 GitHub(或其他代码托管中心)的账号没有任 何关系。</p>
<h3 id="2-git-init-初始化本地库">2. git-init-初始化本地库</h3>
<p><strong>在本地库项目文件夹路径下</strong>,初始化本地库</p>
<pre><code class="language-sh">Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit (master)
$ git init
Initialized empty Git repository in D:/codeProject/HelloGit/.git/
</code></pre>
<h3 id="3-git-status-查看本地库状态">3. git status-查看本地库状态</h3>
<pre><code class="language-shell">Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit (master)
$ git status
On branch master当前分支名
No commits yet 提交的文件
Untracked files:未被追踪的文件
(use "git add <file>..." to include in what will be committed)
hello.txt
nothing to commit (create/copy files and use "git add" to track)
</code></pre>
<h3 id="4-git-add-添加暂存区">4. git add-添加暂存区</h3>
<p>让文件可以被追踪到。</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git add 文件名</td>
<td>添加文件到暂存区</td>
</tr>
<tr>
<td>git rm --cached 文件名</td>
<td>删除暂存区文件</td>
</tr>
</tbody>
</table>
<pre><code class="language-shell">$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt. 自动转换换行符警告
The file will have its original line endings in your working directory
$ git rm --cached hello.txt
</code></pre>
<h3 id="5-git-commit-提交本地库">5. git commit-提交本地库</h3>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git commit -m "版本信息" 文件名</td>
<td>将暂存区的文件提交到本地库</td>
</tr>
<tr>
<td>git reflog</td>
<td>查看日志</td>
</tr>
<tr>
<td>git log</td>
<td>查看详细日志</td>
</tr>
</tbody>
</table>
<pre><code class="language-shell">$ git commit -m "firstCommit" hello.txt
$ git status
On branch master
nothing to commit, working tree clean
$ git reflog
6ab51f3 (HEAD -> master) HEAD@{0}: commit (initial): firstCommit
$ git log
commit 6ab51f358830f2df4a3abb0412b917e3840c7732 (HEAD -> master)
Author: Vicstal <2428991957@qq.com>
Date: Wed Jun 1 19:27:53 2022 +0800
firstCommit
</code></pre>
<h3 id="6-更新文件">6. 更新文件</h3>
<pre><code class="language-shell">$ vim hello.txt
$ git add hello.txt
$ git status
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: hello.txt 可追踪的文件
$ git commit -m "v3.0" hello.txt
1 file changed, 1 insertion(+), 1 deletion(-) 1处修改 1行新增 1行删除
$ git reflog
685fd80 (HEAD -> master) HEAD@{0}: commit: v3.0 现在指向3.0版本
c229daa HEAD@{1}: commit: v2.0
6ab51f3 HEAD@{2}: commit (initial): firstCommit
</code></pre>
<h3 id="7-git-reset-版本穿梭">7. git reset-版本穿梭</h3>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git reset --hard 7位版本号</td>
<td>版本穿梭</td>
</tr>
</tbody>
</table>
<pre><code class="language-shell">$ git reset --hard c229daa
HEAD is now at c229daa v2.0
</code></pre>
<h2 id="四git分支">四、Git分支</h2>
<h3 id="1-git分支">1. Git分支</h3>
<p>项目的版本控制中,可以有多个分支应对不同种任务。分支从主线中分离开来,不会影响主线运行。</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222552497-1589330099.png" alt="image-20220601195451995" loading="lazy"></p>
<p>优点:</p>
<ul>
<li>同时并行推进多个功能开发,提高开发效率</li>
<li>分支开发失败,不会对其他分支有任何影响。失败的分支删除重新开始即可。</li>
</ul>
<h3 id="2-常用命令">2. <strong>常用命令</strong></h3>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git branch 分支名</td>
<td>创建分支</td>
</tr>
<tr>
<td>git branch -v</td>
<td>查看分支</td>
</tr>
<tr>
<td>git checkout 分支名</td>
<td>切换分支</td>
</tr>
<tr>
<td>git merge 分支名</td>
<td>将指定分支合并到当前分支上</td>
</tr>
</tbody>
</table>
<h3 id="3-合并分支">3. <strong>合并分支</strong></h3>
<pre><code class="language-shell">$ git branch hot-fix
$ git branch -v
hot-fix 6436445 hot-fix v1.0
* master685fd80 v3.0
$ git checkout hot-fix
$ vim hello.txt
$ git add hello.txt
$ git commit "hot-fix v1.0" hello.txt
$ git checkout master
$ git merge hot-fix
Updating 685fd80..6436445
Fast-forward
hello.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
</code></pre>
<h3 id="4-合并分支代码冲突">4. 合并分支(代码冲突)</h3>
<p>合并分支时,两个分支在<strong>同一个文件的同一个位置</strong>有两套完全不同的修改。Git 无法替 我们决定使用哪一个。必须<strong>人为决定</strong>新代码内容。</p>
<p><strong>合并冲突问题:</strong></p>
<pre><code class="language-shell">#hot-fix分支的hello.txt
hello, git 55555
hello, git
#master分支的hello.txt
hello, git
hello, git 66666
#在master分支下合并,失败
$ git merge hot-fix
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit (master|MERGING)
</code></pre>
<p><strong>冲突文件:</strong></p>
<pre><code><<<<<<< HEAD
hello, git 555555
hello, git
=======
hello, git
hello, git 6666666
>>>>>>> hot-fix
</code></pre>
<p><strong>解决方法:</strong></p>
<ol>
<li>
<p>自己修改冲突文件,保留需要的代码</p>
<pre><code>hello, git 555555
hello, git 6666666
</code></pre>
</li>
<li>
<p>将冲突文件添加到暂存区</p>
<pre><code class="language-shell">$ git add hello.txt
</code></pre>
</li>
<li>
<p>执行提交(注意:此时使用 git commit 命令时不能带文件名)</p>
<pre><code class="language-shell">git commit -m "v5.0"
</code></pre>
</li>
</ol>
<p><strong>分支原理</strong></p>
<ul>
<li>master、hot-fix 其实都是指向具体版本记录的指针。所以创建分支的本质就是多创建一个指针</li>
<li>当前所在的分支,其实是由 HEAD 决定的。</li>
<li>HEAD 如果指向 master,那么我们现在就在 master 分支上。 HEAD 如果执行 hotfix,那么我们现在就在 hotfix 分支上。</li>
</ul>
<h2 id="五git代码托管中心">五、Git代码托管中心</h2>
<h3 id="1-团队协作">1. 团队协作</h3>
<p>通过pull, push, clone更新获取代码</p>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222621679-1942219842.png" alt="image-20220602122132733" style="zoom: 67%">
<h3 id="2-跨团队协作">2. 跨团队协作</h3>
<p>跨团队通过fork项目 ➡修改代码 ➡ push提交 ➡ 发送pull 请求 ➡ 当前团队通过merge合并代码</p>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222639090-1541196786.png" alt="image-20220602122122445" style="zoom: 67%">
<h2 id="六github">六、GitHub</h2>
<p>远程仓库操作</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git remote -v</td>
<td>查看远程仓库别名</td>
</tr>
<tr>
<td>git remote add 别名 远程地址</td>
<td>为远程仓库起别名</td>
</tr>
<tr>
<td>git push 别名 分支</td>
<td>将本地分支推送到远程仓库</td>
</tr>
<tr>
<td>git clone 远程地址</td>
<td>将远程仓库的内容克隆到本地</td>
</tr>
<tr>
<td>git pull 远程仓库地址别名 远程分支名</td>
<td>将远程仓库对于最新内容拉下来后与本地分支合并</td>
</tr>
</tbody>
</table>
<h3 id="1-创建远程仓库别名">1. 创建远程仓库别名</h3>
<p>为使用的远程仓库创建别名,便于方便和管理</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git remote add 别名 远程地址</td>
<td>为远程仓库起别名</td>
</tr>
</tbody>
</table>
<pre><code class="language-shell">$ git remote add HelloGit https://github.com/Vicstal/HelloGit.git
$ git remote -v
HelloGit https://github.com/Vicstal/HelloGit.git (fetch) 拉取别名
HelloGit https://github.com/Vicstal/HelloGit.git (push)推送别名
</code></pre>
<h3 id="2-git-push-推送本地分支到远程仓库">2. git push-推送本地分支到远程仓库</h3>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git push 别名/地址 分支</td>
<td>将本地分支推送到远程仓库</td>
</tr>
</tbody>
</table>
<p>需要登录GitHub账户</p>
<pre><code class="language-shell">Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit (master)
$ git push HelloGit master
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 16 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (21/21), 1.49 KiB | 508.00 KiB/s, done.
Total 21 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), done.
To https://github.com/Vicstal/HelloGit.git
* master -> master
</code></pre>
<h3 id="3-git-pull-拉取远程仓库到本地分支">3. git pull-拉取远程仓库到本地分支</h3>
<p>拉取远程仓库最新分支到本地</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git pull 别名 分支名</td>
<td>将远程仓库对于最新内容拉下来后与本地分支合并</td>
</tr>
</tbody>
</table>
<pre><code class="language-shell">$ git pull HelloGit master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 641 bytes | 80.00 KiB/s, done.
From https://github.com/Vicstal/HelloGit
* branch master -> FETCH_HEAD
a66faf6..0879bbfmaster -> HelloGit/master
Updating a66faf6..0879bbf
Fast-forward
hello.txt | 1 +
1 file changed, 1 insertion(+)
</code></pre>
<h3 id="4-git-clone-克隆远程仓库">4. git clone-克隆远程仓库</h3>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>git clone 远程地址</td>
<td>将远程仓库的内容克隆到本地</td>
</tr>
</tbody>
</table>
<p>无需登录,clone 会做如下操作:</p>
<ul>
<li>拉取代码</li>
<li>初始化本地仓库</li>
<li>创建别名</li>
</ul>
<pre><code class="language-shell">$ git clone https://github.com/Vicstal/HelloGit.git
Cloning into 'HelloGit'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 24 (delta 8), reused 20 (delta 7), pack-reused 0
Receiving objects: 100% (24/24), done.
Resolving deltas: 100% (8/8), done.
#clone自动创建别名
Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit2/HelloGit (master)
$ git remote -v
originhttps://github.com/Vicstal/HelloGit.git (fetch)
originhttps://github.com/Vicstal/HelloGit.git (push)
</code></pre>
<h3 id="5-本地团队合作">5. 本地团队合作</h3>
<p>模拟其他团队操作仓库</p>
<h4 id="51-克隆分支">5.1 克隆分支</h4>
<pre><code class="language-shell"># 在文件夹下clone项目
Sang@LAPTOP-CF4TUDVT MINGW64 /d/codeProject/HelloGit2 (master)
$ git clone https://github.com/Vicstal/HelloGit.git
#进入HelloGit2/HelloGit克隆的项目里
#在windows的凭证管理器中删除GitHub账号名
</code></pre>
<h4 id="52-邀请加入团队">5.2 邀请加入团队</h4>
<p>Github库</p>
<p>➡ settings ➡ Manage access ➡ Invite a collaborator</p>
<p>➡ 输入成员名</p>
<p>➡ 复制邀请函Pending Invite ➡ 团队成员接受邀请 Accept invitation</p>
<h4 id="53-拉取推送分支">5.3 拉取推送分支</h4>
<p>成功之后可以在 atguigulinghuchong 这个账号上看到 git-Test 的远程仓库。并可以推送到远程仓库:</p>
<pre><code class="language-shell">$ git push HelloGit master
Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': atguigulinghuchong
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 309 bytes | 309.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/atguiguyueyue/git-shTest.git
7cb4d02..5dabe6b master -> master
$ git pull HelloGit master
</code></pre>
<h3 id="6-跨团队合作">6. 跨团队合作</h3>
<h4 id="61-fork分支">6.1 fork分支</h4>
<p>跨团队要想合作,首相fork远程仓库到本地库</p>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222722199-1351951230.png" alt="image-20220602144056747" style="zoom: 67%">
<p>在本地修改代码,并推送</p>
<pre><code class="language-shell">$ git pull git-shTest master
$ vim hello.py
$ git add hello.py
$ git commit
$ git push git-shTest master
</code></pre>
<h4 id="62-跨团队merge分支">6.2 跨团队merge分支</h4>
<ol>
<li>其他团队提交pull请求</li>
</ol>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222806026-731332408.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222810220-1561716731.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222814522-410378987.png" alt="" loading="lazy"></p>
<ol start="2">
<li>自己他团队merge请求<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222834503-885611356.png" alt="" loading="lazy"></li>
</ol>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222838896-1746641189.png" alt="" loading="lazy"></p>
<h3 id="7-ssh免密登录">7. SSH免密登录</h3>
<ol>
<li>生成SSH:如果已有ssh,在C:/user/用户名下删除.ssh, 进入bash</li>
</ol>
<pre><code class="language-shell"># 运行命令生成.ssh 秘钥目录
$ ssh-keygen -t rsa -C 远程仓库github名
$ 三次回车
# 打开id_rsa.pub,复制
</code></pre>
<ol start="2">
<li>
<p>添加SSH</p>
<p>复制 id_rsa.pub 文件内容,登录 GitHub,点击用户头像 ➡ Settings ➡ SSH and GPG keys ➡ new SSH key ➡ Title:随意, Key:复制的公钥 ➡ Add SSHKey</p>
</li>
<li>
<p>免密拉取,推送分支</p>
</li>
</ol>
<pre><code>git push/pull SSH连接 分支名
</code></pre>
<h2 id="七idea集成git">七、Idea集成Git</h2>
<h3 id="1-配置git忽略文件">1. 配置Git忽略文件</h3>
<p>在使用idea集成git时,设置需要忽略的文件,这些文件不参与服务器上部署运行,把它们忽略掉能屏蔽IDE工具之间的差异。</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222855073-867591426.png" alt="" loading="lazy"></p>
<ol>
<li>
<p>在C:/Users/用户名下创建git.ignore</p>
<pre><code># Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see
http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.classpath
.project
.settings
target
.idea
*.iml
</code></pre>
</li>
<li>
<p>在C:/Users/用户名/.gitconfig 文件中引用忽略配置文件</p>
<pre><code>
name = Layne
email = Layne@atguigu.com
excludesfile = C:/Users/Sang/git.ignore
</code></pre>
<blockquote>
<p>注意:这里要使用“正斜线(/)”,不要使用“反斜线(\)”</p>
</blockquote>
</li>
</ol>
<h3 id="2-idea集成git">2. Idea集成Git</h3>
<p><strong>集成Git</strong></p>
<p>settings ➡ 设置Git安装目录<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222905823-494197289.png" alt="" loading="lazy"></p>
<p><strong>将项目添加到版本控制</strong></p>
<p>➡ VCS➡ Enabled Version Control Integration</p>
<p><strong>将代码添加到暂存区</strong></p>
<p>代码文件 ➡ 右键 ➡ Git ➡ +Add</p>
<p><strong>将项目添加到暂存区</strong></p>
<p>项目 ➡ 右键 ➡ Git ➡ +Add</p>
<p><strong>将项目添加到本地库</strong></p>
<p>项目 ➡ 右键 ➡ Git➡ commit Directory<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222931634-1844335206.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222936239-2064679857.png" alt="" loading="lazy"></p>
<h3 id="3-切换版本">3. 切换版本</h3>
<ol>
<li>点击Git</li>
<li>点击Log</li>
<li>在切换的版本上右键 → checkout Revision 'a40001aa'</li>
</ol>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222945659-732988863.png" alt="" loading="lazy"></p>
<h3 id="4-创建分支">4. 创建分支</h3>
<ol>
<li>
<p>点击new Branch<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608222954978-1052193659.png" alt="" loading="lazy"></p>
</li>
<li>
<p>创建新分支</p>
<img src="Git.assets/image-20220608115027021.png" alt="image-20220608115027021" style="zoom: 80%">
</li>
</ol>
<h3 id="5-合并分支">5. 合并分支</h3>
<ol>
<li>点击分支按钮</li>
<li>点击要合并的分支</li>
<li>合并:Merge into current</li>
</ol>
<p><img src="Git.assets/image-20220608115223718.png" alt="image-20220608115223718" loading="lazy"></p>
<h3 id="6-合并分支有冲突">6. 合并分支——有冲突</h3>
<ol>
<li>
<p>master合并hot-fix分支<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223039939-117904164.png" alt="" loading="lazy"></p>
</li>
<li>
<p>自定义冲突<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223049357-1337400411.png" alt="" loading="lazy"></p>
</li>
</ol>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223054783-1290264462.png" alt="" loading="lazy"></p>
<h2 id="八github">八、GitHub</h2>
<h3 id="1-设置github账号">1. 设置GitHub账号</h3>
<p>setting ➡ version control➡ Github ➡ 点击加号 ➡ 通过token登录github</p>
<p>https://blog.csdn.net/qq_44866828/article/details/118084398</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223113425-39965810.png" alt="" loading="lazy"></p>
<p>➡通过Github令牌登录</p>
<p>https://blog.csdn.net/qq_44866828/article/details/118084398</p>
<h3 id="2-将项目分享到github">2. 将项目分享到Github</h3>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223124483-440448784.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223132162-857550445.png" alt="" loading="lazy"></p>
<p>底下可以看到推送成功信息<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223142104-606270512.png" alt="" loading="lazy"></p>
<h3 id="3-push项目到github">3. Push项目到github</h3>
<ol>
<li>
<p>点击push箭头</p>
</li>
<li>
<p>点击项目名,define remote</p>
</li>
<li>
<p>改为SSH连接推送项目<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223205332-1438738507.png" alt="" loading="lazy"></p>
</li>
<li>
<p>选择SSH连接的项目,push<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223210866-839525342.png" alt="" loading="lazy"></p>
</li>
</ol>
<blockquote>
<p>注意:</p>
<p>push 是将本地库代码推送到远程库,如果本地库代码跟远程库代码版本不一致, push 的操作是会被拒绝的。</p>
<p>要想 push 成功,一定要保证本地库的版本要比远程 库的版本高!</p>
<p>因此一个成熟的程序员在动手改本地代码之前,一定会先检查下远程库跟本地 代码的区别!如果本地的代码版本已经落后,切记要先 pull 拉取一下远程库的代码,将本地 代码更新到最新以后,然后再修改,提交,推送!</p>
</blockquote>
<h3 id="4-pull项目到本地">4. Pull项目到本地</h3>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223228273-1239236253.png" alt="" loading="lazy"></p>
<h3 id="5-clone项目">5. clone项目</h3>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223232575-491493363.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223236777-139539516.png" alt="" loading="lazy"></p>
<h2 id="九gitee">九、Gitee</h2>
<h3 id="1-创建仓库">1. 创建仓库</h3>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223251112-614865771.png" alt="" loading="lazy"></p>
<h3 id="2-idea集成gitee">2. IDEA集成Gitee</h3>
<ol>
<li>
<p>Idea安装Gitee插件</p>
<p>setttings ➡ Plugins ➡ Gitee ➡ install</p>
</li>
<li>
<p>在idea中登录gitee账号</p>
<p>settings➡Log in via Gitee</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223310159-1722603288.png" alt="" loading="lazy"></p>
<p>➡ 登录账号密码</p>
</li>
</ol>
<h3 id="3-push推送到指定仓库中">3. push推送到指定仓库中</h3>
<p>push代码时,自定义仓库连接到指定位置<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223326132-306259452.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223330530-561463279.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223334325-556493798.png" alt="" loading="lazy"></p>
<h3 id="4-pull远程项目到本地">4. pull远程项目到本地</h3>
<p>Git → Pull到本地<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223346714-19855026.png" alt="" loading="lazy"></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223350729-1897601540.png" alt="" loading="lazy"></p>
<h3 id="5-克隆github项目到gitee">5. 克隆Github项目到Gitee</h3>
<p>+➡ 新建仓库 ➡ 已有仓库 ➡ 将Github的Https连接复制过来</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223404565-1443678850.png" alt="" loading="lazy"></p>
<p><strong>更新项目</strong></p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223410982-1967937089.png" alt="" loading="lazy"></p>
<h2 id="十gitlab">十、GitLab</h2>
<p>开源的用户自建代码托管平台工具,仅支持CentOS7以上系统。官网地址:https://about.gitlab.com/</p>
<h3 id="1-gitlab安装">1. GitLab安装</h3>
<ol>
<li>
<p>准备好一台CentOS主机,修改Ip地址和主机名</p>
<p>修改ip地址:</p>
<pre><code class="language-shell">vim /etc/sysconfig/network-scripts/ifcfg-ens160
</code></pre>
<p>或者直接修改VMWare,修改ip地址</p>
<p><img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223423890-1637425326.png" alt="" loading="lazy"></p>
<p>修改主机名:</p>
<pre><code class="language-shell">$ vim /etc/hostname
gitlab-server(主机名)
</code></pre>
</li>
<li>
<p>配置hosts, 将服务器主机名映射到对应的服务器ip地址</p>
<pre><code>192.168.131.128 gitlab-server
</code></pre>
</li>
<li>
<p>安装gitlab</p>
<ul>
<li>
<p>在/opt/module文件下上传文件gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm</p>
</li>
<li>
<p>在module下创建gitlab-install.sh</p>
<pre><code class="language-shell">sudo rpm -ivh /opt/module/gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm
sudo yum install -y curl policycoreutils-python openssh-server cronie
sudo lokkit -s http -s ssh
sudo yum install -y postfix
sudo service postfix start
sudo chkconfig postfix on
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" yum -y install gitlab-ce
</code></pre>
<pre><code class="language-shell">$ chmod +x gitlab-install.sh
</code></pre>
</li>
<li>
<p>执行gitlab-install.sh</p>
<pre><code class="language-shell"># ./gitlab-install.sh
</code></pre>
<blockquote>
<p>报错:Errors during downloading metadata for repository ‘AppStream‘</p>
<p>处理:https://blog.csdn.net/xiexingchen_y/article/details/123211959</p>
</blockquote>
</li>
</ul>
</li>
</ol>
<h3 id="2-gitlab使用">2. Gitlab使用</h3>
<ol>
<li>
<p>初始化Gitlab服务</p>
<pre><code class="language-shell"># gitlab-ctl reconfigure
</code></pre>
</li>
<li>
<p>启动Gitlab服务</p>
<pre><code class="language-shell"># gitlab-ctl start
</code></pre>
</li>
</ol>
<h3 id="3-gitlab创建远程仓库">3. Gitlab创建远程仓库</h3>
<ol>
<li>
<p>访问gitlab地址</p>
<pre><code>192.168.131.128:80
gitlab-server (已配置centos主机名和hosts映射)
</code></pre>
</li>
<li>
<p>修改root原始密码</p>
</li>
<li>
<p>登录gitlab</p>
<pre><code>user: root
password:
</code></pre>
</li>
</ol>
<h3 id="4-push项目到gitlab">4. Push项目到Gitlab</h3>
<p>push, 选择 gitlab 远程连接<br>
<img src="https://img2022.cnblogs.com/blog/2673925/202206/2673925-20220608223440169-848037859.png" alt="" loading="lazy"></p>
<blockquote>
<p>注意:gitlab 网页上复制过来的连接是:http://gitlab.example.com/root/git-test.git, 需要手动修改为:http://gitlab-server/root/git-test.git</p>
</blockquote><br><br>
来源:https://www.cnblogs.com/greengages/p/16357544.html
頁:
[1]