# gitpush-http-ssh **Repository Path**: DJYI/gitpush-http-ssh ## Basic Information - **Project Name**: gitpush-http-ssh - **Description**: 这是一个git的测试案例,用于push命令分别用http和ssh方式提交,并提供了git的学习笔记 - **Primary Language**: Java - **License**: Zlib - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2023-01-18 - **Last Updated**: 2025-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: Java, Git ## README # git的使用(可以结合Linux的命令使用) ## 一、git的的概述 ### ①.git的工作机制 ![git的工作机制](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/git的工作机制.png) ### ②公司Git分支管理流程是什么样的? ```bash 稳定版代码主要维护在 master 分支,我们开发小组通常都在 dev 分支进行功能的 开发,当一个版本的功能开发完成后,将其合并到 test 分支,由该分支发版去进行 测试,如果有后续开发功能,我们继续在 dev 进行开发,当测试分支测试有问题时, 我们在测试分支进行修复,修复后确认没有问题了,会重新合并到 dev 分支,并且将 测试完成的代码合并到 master 进行线上版本的发布。 如果 master 发现了 bug, 会直接基于 master 切换出一个新的 bugfix 分支, 在该分支解决 bug, 当 bug 解决后,会进行测试,确认测试通过后,将其重新发布 ,并将修复后的代码合并到 dev 分支。 如果代码出现了冲突,首先看冲突的情况,如果能确定哪些代码需要保留,哪些不需 要,就直接进行合并,如果有不确定的代码一般时找到对应的同事,确认后再合并。 ``` ## 二、git的使用 **git下载官网:** https://git-scm.com/download/win **git下载** ![git下载官网](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/git下载官网.png) **git安装教程** https://blog.csdn.net/sanxd/article/details/82624127 **推送到远程仓库显示介绍** gitee上的README.md必须要这个名字才可以显示出来在首页,可以用本地编写完推送上去就可以了 ### ①设置签名 ​ 目的:用来记录谁提交版本的信息标准 ``` git config --global user.name 用户名 git config --global user.email 邮箱 ``` ``` 设置签名示例: git config --global user.name zhangsan git config --global user.email zhangsan@qq.com 查看是否配置成功: 在C:\Users\ASUS\.gitconfig 下[user]可以看到,证明设置签名成功 ``` 初次推送到远程仓库,输入账号和密码,下次则不需要输入,因为会把账号和密码保存在:凭据管理器,下次则直接从凭据管理器中拿。 > ![凭据管理器](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/凭据管理器.png) ### ②git的常用命令 | 命令名称 | 作作用 | | --------------------------------- | ------------------------------------------------------------ | | git init | 初始化本地仓库 | | git status | 查看本地库状态 | | git add 文件名 | 添加到暂存区 | | git add . | 添加所有变化的文件到暂存区(点.通配符) | | git commit -m "版本说明" 文件名 | 提交到本地库 添加整个文件到本地库:git commit -m "版本说明" | | git reflog | 查看历史记录 | | git log | 查看详细的历史记录 | | git reset --hard 版本号 | 版本穿梭 | | git rm --cached 文件名 | 删除暂存区的文件 | **注意: 工作区和暂存区可以删除文件,本地库不能删除** ``` git的常用命令使用: git status 查看当前本地的状态,三种状态: 状态1.当出现working tree clean 当前工作群分支被清空,证明没有需要添加到暂存区的代码,也就是没有变化 状态2.当出现modified: 文件名 是红色的,证明有变化,需要将文件添加到暂存区 git add 文件名 状态3.当出现modified: 文件名 是绿色的,证明当前已经添加到暂存区,需要提交到本地库 git commit -m "版本说明" 文件名 git reflog 查看历史记录 git log 查看详细的历史记录 git reset --hard b67811d test.txt 回到b67811d这个版本 ``` ③语句解析 ![语句解析](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/语句解析.png) 当前git所处的位置(当前所处分支) /e/java/javadownload/Eclipse/gitDemo 当前git所处的位置 (master) 当前所处的分支 ``` .git\HEAD 里面指当前是哪个分支 .git\refs\heads\分支名 可以查看当前哪个分支是哪个版本 ``` ### ③git的分支 #### 1、什么是git的分支 分支:在版本控制过程中,同时推进多个任务,为每个任务,我们就可以创建每个任务的单独 分支。使用分支意味着程序员可以把自己的工作从开发主线上分离开来,开发自己分支的时 候,不会影响主线分支的运行。对于初学者而言,分支可以简单理解为副本,一个分支就是 一个单独的副本。(分支底层其实也是指针的引用) **图示理解:** ![分支的图解](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/分支的图解.png) **分支的好处:** ​ 同时并行推进多个功能开发,提高开发效率 ​ 各个分支在开发过程中,如果某一个分支开发失败,不会对其他分支有任何影响.失败的分支删除重新开始即可。 **开发中分支使用原则与流程:** > 几乎所有的版本控制系统都以某种形式支持分支。使用分支意味着你可以把你的工作从开发主线上分离开来进行重大的Bug修改、开发新的功能,以免影响开发主线。 > 在开发中,一般有如下分支使用原则与流程: > > - master(生产)分支 > 线上分支,主分支,中小规模项目作为线上运行的应用对应的分支; > - develop(开发)分支 > 是从master创建的分支,一般作为开发部门的主要开发分支,如果没有其他并行开发不同期上线 > 要求,都可以在此版本进行开发,阶段开发完成后,需要是合并到master分支,准备上线。 > - feature/xxoxx分支 > 从develop创建的分支一般是同期并行开发,但不同期上线时创建的分支,分支上的研发任务完 > 成后合并到develop分支。 > - hotfix/xoxxx分支 > 从master派生的分支,一般作为线上bug修复使用,修复完成后需要合并到master、test、develop分支。 > 还有一些其他分支,在此不再详述,例如test分支(用于代码测试)、pre分支(预上线分支)等 #### 2、分支的命令 | 命令 | 作用 | | ---------------------- | ------------------------------------------------------- | | git branch 分支名 | 创建分支 | | git branch -v | 查看本地所有分支 (-v表示详细查看,也可以直接git branch) | | git checkout 分支名 | 切换到指定的分支 | | git checkout -b 分支名 | 创建一个分支并切换到该分支 | | git merge 分支名 | 把指定的分支合并到当前分支上 | | | 删除分支(注:不能删除当前分支,只能删除其他分支) | | git branch -d 分支名 | 删除分支时,需要做各种检查,一步一步确认删除 | | git branch -D 分支名 | 不做任何检查,强制删除 | ``` 分支命令的使用: git branch hot-fix 创建hot-fix分支 git branch -v 查看所有分支 git checkout hot-fix 当前分支切换到hot-fix分支上 git merge hot-fix 当前分支合并hot-fix分支 ``` #### 4、**合并分支的时 ** 产生冲突 的原因:(检测到文件有两处修改:合并的两个文件都分别有修改就会产生冲突) ``` 合并分支时,两个分支在**同一个文件的同一位置**有两套完全不同的修改。git无法替我们决定使用哪一个。必须**人为决定**新代码内容 ``` **解决分支合并冲突** ``` 1)编辑有冲突的文件,删除特殊符号,决定要使用的内容 如: 特殊符号: <<<<<<< HEAD 当前分支的代码 ======= 合并过来的代码 >>>>>>> hot-fix 修改为我们想使用的内容 如: 剩余我们想使用的代码,删除特殊符号 2)添加到暂存区 git add 文件名 3)提交到本地库(合并分支解决冲突之后,此时会有两个分支的同一文件需要提交,因此不能指定提交的文件名,否则报错) git commit -m "版本说明" 注意:合并分支之后,只会修改我们合并的分支(主分支),不会修改合并过来的分支(次分支) ``` #### 3、创建分支和切换分支图解 ![创建分支和切换分支图解](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建分支和切换分支图解.png) 分支其实是指向具体版本记录的指针。当前所在的分支,其实是由HEAD决定的.所以创建分支的本质就是多创建一个指针。 ​ HEAD如果指向master,那么我们现在就在master分支上 ​ HEAD如果执行hot-fix,那么我们现在就在hot-fix分支上 所以:切换分支的本质是移动HEAD指针 ### ④创建远程仓库&推送远程仓库&拉取远程仓库到本地仓库 | 命令名称 | 作用 | | ------------------------------------------------------ | ------------------------------------------------------------ | | git remote -v | 查看当前远程仓库所有地址的别名 | | git remote add 别名 远程地址 | 给远程仓库的地址起别名 | | git push <远程主机名> <本地分支名>:<远程分支名> | 推送本地仓库分支上的内容到远程仓库 | | git pull 远程库地址别名 远程库分支名 | 将远程仓库对于分支最新内容拉取下来到本地仓库后与当前本地仓库分支直接合并(更新本地仓库,达到本地仓库内容与远程仓库内容同步) | | git clone 远程地址 或 git clone -b 远程分支名 远程地址 | 将远程仓库的内容克隆到本地仓库(clone到本地仓库会自动做以下操作:1、拉取代码 2、初始化本地仓库 3、给远程仓库地址创建别名) | ``` 命令使用: git remote -v 查看当前远程仓库所有地址的别名 git remote add gitDemo https://github.com/DuJiayi127039/gitDemo.git 给远程仓库的地址起别名 git remote remove 别名 删除当前远程仓库的别名 git push gitDemo master 将master分支推出到别名为gitDemo的远程仓库中 ①git push 远程地址 本地分支:远程分支 如:git push https://localhost/demo master:dev ==>表示将本地的master分支提交到https://localhost/demo的远程仓库的dev分支,如果远程蹭课没有该分支会自动创建该分支 ②git push 远程地址别名 本地分支:远程分支 如:git push origin master:dev ==>上述同意思,先用git remote add origin https://localhost/demo再git push origin master:dev ③git push 远程地址别名 当前分支 如:git push origin dev ==>默认将本地分支当前dev分支提交到远程仓库的dev分支 git pull gitDemo master 将别名为gitDemo的远程仓库的master分支拉取到本地仓库中与当前本地仓库分支直接合并(相当更新本地仓库,远程仓库与本地仓库内容同步) git clone https://github.com/DuJiayi127039/gitDemo.git 将远程仓库的内容克隆到本地仓库中 注意:clone到本地仓库与自动做以下操作:1、拉取代码 2、初始化本地仓库 3、给远程仓库地址创建别名 默认克隆远程仓库的主分支(master分支)即:默认分支 git clone https://github.com/DuJiayi127039/gitDemo.git newname 将克隆下来的文件名改为newname //克隆远程仓库指定分支到本地 git clone -b dev https://github.com/DuJiayi127039/gitDemo.git ``` ### ⑤团队协作机制 #### 1、团队内协作 ①在github上先把队员加入到当前项目中 ![github团队协作添加成员1](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/github团队协作添加成员1.png)![github团队协作添加成员2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/github团队协作添加成员2.png) ![成员账号添加](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/成员账号添加.png) ![复制邀请函](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/复制邀请函.png) ②然后让成员登录直接的账号之后,直接把该邀请函复制贴在地址栏搜索,然后同意邀请函,就加入了团队, ③成员也可以提交项目到远程仓库以及克隆以及拉取远程库等 #### 2、跨团队协作 ![跨团队1](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队1.png) ![跨团队2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队2.png) ![跨团队3](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队3.png) ![跨团队4](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队4.png) ![跨团队5](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队5.png) ![跨团队6](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队6.png) ![跨团队7](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/跨团队7.png) ### ⑥SSH免密登录(第二种提交远程仓库的方式,第一种登录的https方式) SSH免密登录官方地址学习:https://gitee.com/help/articles/4181 ​ SSH免密登录:就是只需要在电脑配置一次免密登录,以后提交代码就不需要登录,直接提交就行 ​ HTTPS提交,每次提交都需要进行验证登录 1. 在C:\Users\ASUS 右键git bash here 2. --运行命令生成.ssh 秘钥目录[注意:这里-C 这个参数是大写的 C,-t 什么加密(rsa表示非对称加密)] ssh-keygen -t rsa -C git的签名邮箱 如:ssh-keygen -t rsa -C xxx@123456789qq.com 然后敲三次回车 3. 之后有生成一个.ssh的文件夹 路径:C:\Users\ASUS\.ssh 有两个文件:id_rsa 是私钥,id_rsa.pub是公钥 如图: ![ssh生成公钥和私钥](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/ssh生成公钥和私钥.png) 然后通过git打开公钥,把公钥复制 4. ![SSH免密登录](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/SSH免密登录.png) 5.![SSH免密登录](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/SSH免密登录2.png) 6.![SSH免密登录3](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/SSH免密登录3.png) 7.然后把项目推送到远程仓库就用SSH这个地址进行推送,就不需要登录了 8.在git bash中命令测试公钥是否配置成功:ssh -T git@gitee.com 如图表示配置成功: ## 三、IDEA集成Git ### ①环境配置 1.忽略与项目的实际功能无关,不参与服务器上部署运行的文件,把它们忽略掉。能够与屏蔽IDEA工具之间的差异 2.在C:\Users\ASUS 下创建一个git.ignore文件然后在文件中写要忽略的文件(*.log) ``` 模板如下: # 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 ``` 3.在C:\Users\ASUS\ .gitconfig配置与git.ignore的关联 [core] excludesfile = C:/Users/ASUS/git.ignore 4.在IDEA的setting中配置git的环境 ![IDEA中git的环境配置](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA中git的环境配置.png) ### ②git对项目的管理 #### 1.初始化本地库对该项目的管理 ![IDEA初始化本地库管理该项目](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA初始化本地库管理该项目.png) #### 2.添加暂存区与提交本地库 项目右键(代表整个项目都操作) ![添加暂存区&提交本地库](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/添加暂存区&提交本地库.png) 当添加暂存区:注意发出的警告(要不要把配置的忽略文件添加到git管理,按取消(Cancel),不让Git管理) ![git忽略对一些文件的管理](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/git忽略对一些文件的管理.png) #### 3.查看提交本地库的版本 ![查看提交的版本](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/查看提交的版本.png) #### 4.切换版本(右键:checkout) ![切换版本](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/切换版本.png) #### 5.创建分支与切换分支 查看当前处于哪个分支(IDEA右下角):![当前所处的分支](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/当前所处的分支.png) ![当前所处分支2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/当前所处分支2.png) ##### ①创建分支 ​ 方式1(IDEA的右下角):![创建分支](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建分支.png) ​ 方式2(右键项目):![创建分支方式2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建分支方式2.png) ![](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建分支2.2.png) ##### ②切换分支 ![切换分支](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/切换分支.png) #### 6.合并分支 ##### ①正常合并 ![合并分支](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/合并分支.png) **如果代码没有冲突,分支直接合并成功,分支合并成功以后,代码自动提交,无需手动 提交本地库。** ##### ②合并冲突(需要手动处理合并) **如图所示,如果 master 分支和 hot-fix 分支都修改了代码,在合并分支的时候就会发生 冲突。**![解决合并冲突1](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/解决合并冲突1.png) ![解决合并冲突2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/解决合并冲突2.png) ![解决合并冲突3](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/解决合并冲突3.png) ##### ③分支总结 ![分支总结](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/分支总结.png) ## 四、IDEA集成Github ### ①.登录github账号 在IDEA中的setting中找到github就可以登录了 因为在IDEA中github用账号和密码登录,由于网络问题很难登录成功,因此可以用口令登录 生成口令的方式: ![](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/生成口令1.png) ![开发者设置](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/开发者设置.png) ![口令登录_生成口令](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/口令登录_生成口令.png) ### ②、创建远程库并把项目推送到远程库 ![创建远程库并把项目推送到远程库](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建远程库并把项目推送到远程库.png) ![创建远程库并把项目推送到远程库2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/创建远程库并把项目推送到远程库2.png) ### ③、push 推送本地库到远程库 右键点击项目,可以将当前分支的内容 push 到 GitHub 的远程仓库中。 ![pull推送到远程仓库](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/push推送到远程仓库.png) ![pull推送到远程仓库2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/push推送到远程仓库2.png) #### 方式1:直接推送到远程仓库(默认是使用https方式) #### 方式2:需要手动配置地址别名,然后使用SSH方式免密登录推送到远程仓库 ![pull推送到远程仓库3](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/push推送到远程仓库3.png) ![pull推送到远程仓库4](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/push推送到远程仓库4.png) **注意:push 是将本地库代码推送到远程库,如果本地库代码跟远程库代码版本不一致, push 的操作是会被拒绝的。也就是说,要想 push 成功,一定要保证本地库的版本要比远程 库的版本高!因此一个成熟的程序员在动手改本地代码之前,一定会先检查下远程库跟本地 代码的区别!如果本地的代码版本已经落后,切记要先 pull 拉取一下远程库的代码,将本地 代码更新到最新以后,然后再修改,提交,推送!** ### ④pull 拉取远程库到本地库 右键点击项目,可以将远程仓库的内容 pull 到本地仓库。![pull拉取远程库代码到本地库](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/pull拉取远程库代码到本地库.png) ![pull拉取远程库代码到本地库](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/pull拉取远程库代码到本地库2.png) **注意:pull 是拉取远端仓库代码到本地,如果远程库代码和本地库代码不一致,会自动 合并,如果自动合并失败,还会涉及到手动解决冲突的问题。** ### ⑤clone 克隆远程库到本地 ![clone克隆远程库项目到本地](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/clone克隆远程库项目到本地.png) ![clone克隆远程库项目到本地2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/clone克隆远程库项目到本地2.png) ## 五、IDEA集成gitee且能带入github项目与同步代码 gitee操作与github一样就省略了 ### 1.gitee导入github中的项目 ![gitee导入github项目2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/gitee导入github项目2.png) ![gitee新建仓库导入github项目](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/gitee新建仓库导入github项目.png) ### 2.gitee同步github中的项目![gitee更新github项目](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/gitee更新github项目.png) ## 六、IDEA集成gitlab ### 1.搭环境(在linux下) ``` 1.准备一个系统为 CentOS7 以上版本的服务器,要求内存 4G,磁盘 50G。 2.关闭防火墙,并且配置好主机名和 IP,保证服务器可以上网。 (关闭防火墙:systemctl stop firewalld 关闭开启启动项:systemctl disable firewalld) 3.配置静态主机地址:vi /etc/sysconfig/network-scripts/ifcfg-ens33 修改成 TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" UUID="8b3d4553-010d-44e0-a67e-b2f73761bcef" DEVICE="ens33" ONBOOT="yes" ZONE=public # IP地址 IPADDR=192.168.20.131 # 域名解析器(谷歌的) DNS1=8.8.8.8 # 网关 GATEWAY=192.168.20.2 4.在window系统下C:\Windows\System32\drivers\etc\hosts文件中配置ip地址的映射 如:192.168.20.131 gitlab-server ``` ### 2.下载软件 ``` 1.将gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm包复制粘贴到linux的/usr/local/downloadRoot中 2.创建一个文件:touch gitlab-install.sh 内容: sudo rpm -ivh /usr/local/downloadRoot/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/gitlabce/script.rpm.sh | sudo bash sudo EXTERNAL_URL="http://gitlab.example.com" yum -y install gitlabce 3.保存好该文件,给该文件添加执行缺陷:chmod o+x gitlab-install.sh 4.进入到该downloadRoot目录中然后执行该脚本文件:./gitlab-install.sh 5.当出现一只狐狸头像代表安装成功 ``` ### 3.gitlab的操作 ``` 1.初始化gitlab: gitlab-ctl reconfigure 2.启动gitlab: gitlab-ctl start 3.通过浏览器访问配置的ip地址或者window的ip地址名:http://192.168.20.131 4.首次访问需要修改密码(密码要大小写并且特殊符号的8位及以上) ``` ### 4.注册gitlab ``` 用户名(邮箱):root gitlab密码: Gitlab_root_admin ``` ### 5.创建远程仓库 ### 6.IDEA中下载gitlab插件 ![IDEA安装gitlab插件](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA安装gitlab插件.png) 设置gitlab插件 ![IDEA的gitlab插件2](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA的gitlab插件2.png) ![IDEA的gitlab插件3](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA的gitlab插件3.png) ![IDEA的gitlab插件4](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA的gitlab插件4.png) ![IDEA的gitlab插件5](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA的gitlab插件5.png) ![IDEA的gitlab插件6](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/IDEA的gitlab插件6.png) 注意:gitlab 网页上复制过来的连接是:http://gitlab.example.com/root/git-test.git, 需要手动修改为:http://gitlab-server/root/git-test.git 选择 gitlab 远程连接,进行 push。 其他push,pull,clone跟github与gitee一样就省略了 7.GitLab上的SSH免密登录和GitHub和Gitee一样 ## 七、git进阶 ### ①、git 标签 #### 1、贴标签 > 命令:git tag 标签名 提交ID > > 如:git tag v1.0.0 给最新提交贴一个v1.0.0的标签 > > ​ git tag v1.0.0 23478 给指定提交的ID贴一个v1.0.0的标签 > > > > 命令:git tag -a {标签名} -m "标签信息" 提交ID > > 如:git tag -a v1.0.0 -m "第一个版本正式上线" 23478 #### 2、查看标签 > 命令:git tag 查看当前项目中的所有标签 > > 如:git tag > > > > 命令:git show 查看某个具体标签的信息 > > 如:git show v1.0.0 #### 3、推送标签 注意:默认情况下,`git push`命令不会将标签推送到远程服务器,需要使用以下命令将标签推送到远程服务器: >命令:git push origin 标签名 推送指定标签到origin远程仓库 > >如:git push origin v1.0.0 推送v1.0.0版本标签到origin远程仓库 > > > >命令:git push origin --tags 推送所有标签到origin 远程仓库 > >如:git push origin --tags 推送所有贴标签到origin远程仓库 #### 4、删除标签 > 命令:git tag -d 标签名 删除本地指定标签 > > 如:git tag -d v1.0.0 > > > > 命令:git push origin :refs/tags/标签名 删除远程标签 > > 如:git push origin :refs/tags/v1.0.0 删除远程v1.0.0的标签 #### 5、Git中的标签(tag)与分支(branch)的区别 >branch 是用于管理代码库中不同分支的工具。branch 通常用于开发、调试和合并代码。 > >tag 是用于标记代码库中特定版本的工具。 tag 则用于发布和版本控制。 ### ②、git fetch 和 git pull 区别 #### 1、git fetch ```shell # 获取远程仓库 git fetch 远程 分支 git fetch origin master # 对比区别 git diff origin/master # 合并远程仓库 git merge origin/master ``` #### 2、git pull git pull 相当于 git fetch 以后,接着再 git merge。即 git pull == git fetch + git merge 就是它把下载与合并这两个动作结合到一块儿了。 ```shell git fetch origin git merge origin/master ``` ``` shell # 获取远程仓库 git pull 远程 ``` #### 3、git fetch 和 git pull 区别 ![image-20220615094937227](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/image-20220615094937227.png) ## 八、git推送zip,rar,jar文件到远程仓库 参考文章:https://blog.csdn.net/m0_53623945/article/details/122039894 1、先检查 .ignore 文件是否排除,如果被排除了,则去掉。然后推送到远程仓库 2、如果推送失败,如果是文件大于10M或大于100M。解决方案如下:**借助lfs工具** - 下载lfs功能:git lfs install - 设置要上传的文件类型:git lfs track "*.zip" ​ git lfs track "*.jar" - 然后在当前文件夹下会生成 .gitattributes 的文件 ``` *.zip filter=lfs diff=lfs merge=lfs -text *.jar filter=lfs diff=lfs merge=lfs -text ``` - 添加文件到暂存区:git add .gitattributes ​ git add xxx.zip xxx.jar - 推送到远程仓库:git push origin master - 如果是提交到码云,在同步代码到码云的时候,可能会遇到以下问题: ``` 1、WARNING: Authentication error: Authentication required: LFS only supported repository in paid enterprise. 2、batch response: LFS only supported repository in paid enterprise. ``` **第一个错误可以执行下面操作:** 格式: ``` git config lfs.推送远程仓库地址/info/lfs.locksverify false ``` 如: ```text git config lfs.https://gitee.com/DJYI/sentinel-dashboard-nacos-1.8.5.git/info/lfs.locksverify false ``` **第二个错误是因为付费才可以使用,可以执行下面操作:** ```text rm .git/hooks/pre-push ``` 然后再推送到远程仓库:git push origin master **小结:** ![git的常用命令](https://gitee.com/DJYI/gitpush-http-ssh/raw/master/images/git的常用命令.jpg)