Git Github Gitee GitLab - 实践
<style>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; line-height: 1.6 !important; padding: 16px !important; margin: 16px 0 !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; tab-size: 4 !important; -moz-tab-size: 4 !important; max-width: 100% !important; box-sizing: border-box !important }code { font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow-wrap: normal !important; display: inline !important; background: rgba(0, 0, 0, 0) !important; border: none !important; padding: 0 !important; margin: 0 !important; line-height: inherit !important }
pre code { background: rgba(0, 0, 0, 0) !important; border: 0 !important; border-radius: 0 !important; display: block !important; line-height: 1.6 !important; margin: 0 !important; max-width: none !important; overflow: visible !important; padding: 0 !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; color: inherit !important }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: rgba(112, 128, 144, 1) !important; font-style: italic !important }
.token.punctuation { color: rgba(153, 153, 153, 1) !important }
.token.atrule, .token.attr-value, .token.keyword { color: rgba(0, 119, 170, 1) !important; font-weight: bold !important }
.token.function, .token.class-name { color: rgba(221, 74, 104, 1) !important; font-weight: bold !important }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: rgba(102, 153, 0, 1) !important }
.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: rgba(153, 0, 85, 1) !important }
.cnblogs-markdown pre, .cnblogs-post-body pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; padding: 16px !important; margin: 16px 0 !important }
pre, pre, pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important }</style>
<style>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; line-height: 1.6 !important; padding: 16px !important; margin: 16px 0 !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; tab-size: 4 !important; -moz-tab-size: 4 !important; max-width: 100% !important; box-sizing: border-box !important }
code { font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow-wrap: normal !important; display: inline !important; background: rgba(0, 0, 0, 0) !important; border: none !important; padding: 0 !important; margin: 0 !important; line-height: inherit !important }
p code, li code, td code, h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { background-color: rgba(27, 31, 35, 0.05) !important; border-radius: 3px !important; font-size: 85% !important; margin: 0 !important; padding: 0.2em 0.4em !important; white-space: nowrap !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important }
pre code { background: rgba(0, 0, 0, 0) !important; border: 0 !important; border-radius: 0 !important; display: block !important; line-height: 1.6 !important; margin: 0 !important; max-width: none !important; overflow: visible !important; padding: 0 !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; color: inherit !important }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: rgba(112, 128, 144, 1) !important; font-style: italic !important }
.token.punctuation { color: rgba(153, 153, 153, 1) !important }
.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: rgba(153, 0, 85, 1) !important }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: rgba(102, 153, 0, 1) !important }
.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { color: rgba(154, 110, 58, 1) !important }
.token.atrule, .token.attr-value, .token.keyword { color: rgba(0, 119, 170, 1) !important; font-weight: bold !important }
.token.function, .token.class-name { color: rgba(221, 74, 104, 1) !important; font-weight: bold !important }
.token.regex, .token.important, .token.variable { color: rgba(238, 153, 0, 1) !important }
.language-javascript .token.keyword { color: rgba(0, 0, 255, 1) !important; font-weight: bold !important }
.language-javascript .token.string { color: rgba(0, 128, 0, 1) !important }
.language-javascript .token.number { color: rgba(0, 102, 204, 1) !important }
.language-javascript .token.operator { color: rgba(102, 102, 102, 1) !important }
.language-javascript .token.function { color: rgba(121, 85, 72, 1) !important; font-weight: bold !important }
.language-javascript .token.class-name { color: rgba(46, 125, 50, 1) !important; font-weight: bold !important }
.language-bash .token.function { color: rgba(0, 102, 204, 1) !important }
.language-bash .token.string { color: rgba(0, 128, 0, 1) !important }
.language-bash .token.keyword { color: rgba(0, 0, 255, 1) !important; font-weight: bold !important }
.token { display: inline !important; white-space: inherit !important }
.pre-numbering, .hljs-button, .opt-box, .hide-preCode-box { display: none !important }
.markdown_views pre, #content_views pre, .htmledit_views pre, .prettyprint, .hljs { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important }
.language-javascript, .language-java, .language-python, .language-bash, .language-css, .language-html { white-space: pre !important; word-wrap: normal !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important }
.cnblogs-markdown pre, .cnblogs-post-body pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; padding: 16px !important; margin: 16px 0 !important }
pre, pre, pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important }
pre, pre * { box-sizing: border-box !important }
@media (max-width: 768px) { pre { font-size: 12px !important; padding: 12px !important; overflow-x: auto !important } }</style><div id="content_views" class="htmledit_views atom-one-dark"><p>Git的工作流程</p><p>工作区(Workspace):电脑本地目录,即平时存放项目代码的地方</p><p>暂存区(Index/Stage):临时存放改动信息的地方</p><p>本地仓库(Repository):存放所有提交的版本数据</p><p>远程仓库(Remote):托管代码的服务器,如Github、GItLab等</p><p>在电脑本地的工作区中添加或删除或修改文件</p><p></p><p>将工作区中修改的文件放入暂存区 (git add xxx)</p><p>将暂存区的文件提交到git本地仓库 (git commit)</p><p>将本地仓库推送到远程仓库 (git push)</p><p>从远程仓库中拉取到本地 (git pull)</p><p></p><p>Git的常用命令</p>
<pre data-index="0" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-sql">git initgit add README.mdgit commit -m "first commit”第一次提交git branch -M maingit remote add origin https://github.com/Cynthia-shi/库名字.gitgit push -u origin main</code></pre>
<p></p><h4>================Git===================================</h4><p>Git介绍</p><p>Git是分布式版本控制工具,用来管理本地的代码工程,它可以记录代码内容的变更。</p><p></p><p>Git常见操作</p><p>初始化本地仓库</p>
<pre data-index="1" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-bash">git init # 方法一:cd到想要创建本地仓库的目录后,使用以下命令,此时目录中会生成一个.git文件夹git clone https:github.com/xxx/xxx.git # 方法二:从远程仓库克隆一个仓库</code></pre>
<p>设置用户名 邮箱</p>
<pre data-index="2" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-lua">git config --global user.name “six”git config --global user.email sxx@sina.com</code></pre>
<p>将已修改文件添加至暂存区</p>
<pre data-index="3" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-csharp">git add filename # 添加指定的文件到暂存区git add . # 添加所有已修改的文件到暂存区</code></pre>
<p>查看本地库状态</p>
<pre data-index="4" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-lua">git status</code></pre>
<p>将暂存区的文件提交到git本地仓库</p>
<pre data-index="5" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-sql">git commit -m "第一次修改" # ""中是本次修改的简要信息说明注释</code></pre>
<p>查看日志</p>
<pre data-index="6" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-perl">git reflog # 查看版本信息Git log # 查看详细版本信息</code></pre>
<p>版本穿梭</p>
<pre data-index="7" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-perl">git reset --hard 版本号 # 回到(版本号)版本</code></pre>
<p>查看用户名 邮箱</p>
<pre data-index="8" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-lua">git config user.namegit config user.email</code></pre>
<p>查看其他配置信息</p>
<pre data-index="9" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-lua">git config --list</code></pre>
<p>查看git版本</p>
<pre data-index="10" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-sql">git --version</code></pre>
<p>删除仓库有好几个不同的涵义:</p>
<pre data-index="11" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-bash">断开本地git仓库与远程仓库的链接:git remote rm origin删除远程仓库: 删除github的仓库repository删除git本地仓库: rm -rf .git</code></pre>
<p>标签 tag</p>
<pre data-index="12" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-ruby">git tag # 列举所有标签git tag -1 "V1.*" # 列举包含指定字符的标签git tag -a v1.0 -m "标签附注信息" # 创建标签git push origin# 推送标签git push origin --tags # 推送所有标签git tag -d# 删掉本地仓库上的指定标签git push remote :refs/tags/ # 上述指令不会删除远程仓库中的标签,需使用这个命令来更新远程仓库git checkout v1.0 # 切换标签 将git仓库的HEAD指针指向vi.0标签所在的提交</code></pre>
<p>Git分支</p>
<pre data-index="13" class="new-version hljs set-code-height set-code-hide" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-cobol">查看分支(初始时git中只有一个master分支)git branch -v 新建一个分支git branch 分支名 #创建一个新分支git checkout -b 分支名 # 创建一个新分支并切换到该分支 切换分支git checkout 分支名 # 切换到(分支名)分支 合并分支git merge 分支名 # 将分支合并到master上 合并分支冲突git merge 分支名 -> 两个分支都有修改则合并冲突报错 -> 手动修改文件删掉指针和字符 -> git add . -> git commit -m “备注”# 将分支合并到master上</code></pre>
<p></p><p>Git团队协作机制</p><p>团队内协作</p><p>跨团队协作</p><p></p><h4>===============Github=================================</h4><p>Github介绍</p><p></p><p>Github是一个代码托管平台,可以使用Git将本地代码上传到Github 。</p><p>GitHub网址:https://github.com</p><p></p><p>Github常见操作:</p>
<pre data-index="14" class="new-version hljs set-code-height set-code-hide" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-cobol">创建远程库登陆GitHub点击右上角的+号 -> New repository -> 命名 -> 公有库/私有库 -> Creat repository 查看远程库别名(一个远程库两个别名推送拉取)git remote -v 创建远程库别名git remote add 远程库别名 远程库地址 推送本地分支到远程库git push 远程库别名 本地分支名 拉取远程库到本地库git pull 远程库别名 远程分支名 克隆远程库到本地git clone 远程库地址</code></pre>
<p>邀请加入团队</p><p>登陆GitHub进入远程库->Settings->Manage access->Invite a collaborator->输入账号邀请->Pending Invite->复制粘贴邀请函发送给成员->成员复制粘贴邀请函并接受邀请</p><p>团队内协作</p><p>团队成员克隆远程库到本地->修改内容->git add .->git commit->git push 远程库别名 本地分支名->或者直接在远程GitHub上修改</p><p>跨团队协作</p><p>协助人:搜索要协作的项目->右上角fork->在线编辑/克隆本地修改代码->提交改后代码->左上角pull request->new pull request->create pull request->核对修改内容,编辑修改标注,与被协助人沟通的话->create pull request</p><p>被协助人:打开项目->左上角pull request后面出现“圈1”->点击pull request->查看协助人的修改文件review change->可评论聊天comment->合并协作人提交的代码merge pull request-> 确认合并confirm merge</p><p>(精准搜索:用户名/项目名)</p><p></p><p>SSH免密登陆</p><p>本地:ssh-keygen生成密钥->一直回车->cat ~/.ssh/id_rsa.pub->复制显示内容</p><p>GitHub:账户头像->settings->SSH and GPG keys->填写标题->粘贴公钥->Add SSH key</p><p>本地:ssh -T git@github.com 验证是否成功</p><p></p><h4>=================Gitee=================================</h4><p>Gitee介绍</p><p>Gitee是一个中国的代码托管平台,可以使用Git将本地代码上传到Gitee 。</p><p>Gitee网址:Gitee - 企业级 DevOps 研发效能平台</p><p></p><p>Gitee常见操作与GitHub类似:</p>
<pre data-index="15" class="new-version hljs set-code-height set-code-hide" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-undefined">创建远程库 推送本地分支到远程库 拉取远程库到本地库 克隆远程库到本地 邀请加入团队 团队内协作 跨团队协作 SSH登陆 Gitee导入GitHub项目</code></pre>
<p></p><h4>================GitLab=================================</h4><p>GitLab介绍</p><p>GitLab是一个公司私有的代码托管平台,局域网代码托管中心。</p><p>GitLab网址:https://about.gitlab.com</p><p></p><p>GitLab常用命令:</p>
<pre data-index="16" class="new-version hljs set-code-show" name="code" style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="hljs language-bash">sudo gitlab-ctl start # 启动所有 gitlab 组件;sudo gitlab-ctl stop # 停止所有 gitlab 组件;sudo gitlab-ctl restart # 重启所有 gitlab 组件;sudo gitlab-ctl status # 查看服务状态;sudo gitlab-ctl reconfigure # 启动服务;sudo vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;sudo gitlab-ctl tail # 查看日志;</code></pre>
<p></p></div><br><br>
来源:https://www.cnblogs.com/ljbguanli/p/18937291
頁:
[1]