Git (三):Tag 标签管理、图形工具、IDEA 集成与 GitLab 私有化部署

本篇是 Git 系列最后一篇,内容包含Tag 标签管理、Git 图形化工具、IDEA 集成 Git、企业级 GitLab 搭建与使用


一、Git Tag 标签管理

Tag 就是给某次提交打一个版本号标记 ,比如 v1.0v2.1,主要用于项目发布、版本归档

1 两种标签类型

  1. 轻量级标签(lightweight) 只是一个指向提交的指针,不存储额外信息。
  2. 附注标签(annotated) 带有版本说明、创建人、时间,是企业正式发布推荐使用。

2 创建标签

bash 复制代码
# 轻量级标签
git tag v1.0.1

# 附注标签(推荐)
git tag -a v1.0.2 -m "发布 v1.0.2 版本"

3 查看标签

bash 复制代码
git tag

4 删除本地标签

bash 复制代码
git tag -d v1.0.1

5 标签推送到远程仓库

标签默认不会自动随 push 上传,必须手动推送。

bash 复制代码
# 推送单个标签
git push origin v1.0.2

# 推送所有本地标签
git push origin --tags

6 拉取远程标签

bash 复制代码
git pull

拉代码时会自动同步远程标签。

7 删除远程标签

bash 复制代码
# 方法1
git push origin :refs/tags/v1.0.1

# 方法2(更直观)
git push origin --delete tag v1.0.1

8 从标签检出分支(发布修复常用)

bash 复制代码
git checkout -b 分支名 标签名
git checkout -b hotfix_v1.0 v1.0

常用于线上版本紧急修复。


二、Git 图形化工具

1 gitk ------ Git 自带图形日志

命令行输入:

bash 复制代码
gitk

可以看到:

  • 提交历史
  • 分支合并图
  • 文件改动
  • 标签、版本

2 git gui ------ 可视化操作界面

bash 复制代码
git gui

支持:

  • 添加文件到暂存区
  • 提交
  • 推送拉取
  • 版本对比
  • 冲突解决

三、IDEA 集成 Git

1 IDEA 配置 Git

  1. 打开 IDEA → File → Settings(Ctrl+Alt+S)
  2. 搜索 Version Control → Git
  3. 选择 Git 安装路径里的 git.exe
  4. 点击 Test 显示绿色成功即配置完成

2 从 IDEA 克隆远程项目

bash 复制代码
VCS → Git → Clone

输入仓库地址,直接克隆到 IDEA。

15.3 IDEA 中创建本地仓库

bash 复制代码
VCS → Import into Version Control → Create Git Repository

4 日常操作(点点点就行)

  • 提交:ctrl+k
  • 推送:ctrl+shift+k
  • 拉取:ctrl+t
  • 切换分支:右下角点击分支名
  • 解决冲突:可视化界面,点选保留哪段代码

IDEA 集成 Git 是企业开发标准方式,效率极高。


四、GitLab 私有化部署

GitHub 是外网平台,公司一般用 GitLab 搭建内网仓库

1 GitLab 是什么?

  • 企业级 Git 仓库管理平台
  • 功能和 GitHub 几乎一样
  • 私有化部署、安全、免费社区版
  • 支持权限管理、issue、CI/CD、代码审查

2 环境说明

bash 复制代码
系统:CentOS 7.2
版本:gitlab-ce-10.8.4 社区版

3 安装 GitLab

bash 复制代码
mkdir -p /service/tools
cd /service/tools

yum localinstall -y gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm

或在线安装:

bash 复制代码
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm

4 修改配置

bash 复制代码
vim /etc/gitlab/gitlab.rb

修改访问地址:

bash 复制代码
external_url 'http://192.168.0.108'

重新加载配置:

bash 复制代码
gitlab-ctl reconfigure

5 GitLab 汉化

bash 复制代码
git clone https://gitlab.com/xhang/gitlab.git -b v10.8.4-zh

\cp -rf gitlab/* /opt/gitlab/embedded/service/gitlab-rails/

gitlab-ctl reconfigure

6 GitLab 常用命令

bash 复制代码
gitlab-ctl start         # 启动
gitlab-ctl stop          # 停止
gitlab-ctl restart       # 重启
gitlab-ctl status        # 状态
gitlab-ctl reconfigure   # 重新加载配置
gitlab-ctl tail          # 查看日志

7 登录 GitLab

默认用户:root 第一次登录会让你重置密码。

8 创建项目 + SSH 配置

  1. 创建新项目
  2. 本地上传 SSH 公钥
bash 复制代码
ssh-keygen -t rsa -C "你的邮箱"

id_rsa.pub 内容复制到 GitLab → Profile → SSH Keys。

9 本地关联 GitLab

bash 复制代码
git init
git config --local user.name "zhangsan"
git config --local user.email "zhangsan@126.com"

git remote add origin git@192.168.0.108:root/spring_src.git

git add .
git commit -m "init"
git push -u origin master

10 克隆项目

bash 复制代码
git clone git@192.168.0.108:root/spring_src.git

五、Git 高频命令速查

分支

复制代码
git branch                # 查看
git branch dev            # 创建
git checkout dev          # 切换
git checkout -b dev       # 创建+切换
git merge dev             # 合并
git branch -d dev         # 删除
git branch -D dev         # 强制删除

暂存

bash 复制代码
git stash
git stash list
git stash pop

标签

bash 复制代码
git tag v1.0
git tag -a v1.0 -m "msg"
git push origin --tags
git tag -d v1.0
git push origin --delete tag v1.0

远程

bash 复制代码
git clone 地址
git remote add origin 地址
git push -u origin master
git pull
git push

回退

bash 复制代码
git log
git reset --hard HEAD^
git reflog

忽略

bash 复制代码
.gitignore

对比

bash 复制代码
git diff
git diff --cached
相关推荐
桀人4 小时前
类和对象——下
开发语言·c++
十子木4 小时前
git 如何恢复特定版本的内容
linux·git
froginwe114 小时前
Matplotlib 中文显示
开发语言
2601_953660374 小时前
File类
linux·开发语言·python
GIOTTO情4 小时前
Infoseek 媒介投放 API 实战:基于 Python 的全流程自动化方案摘要
开发语言·python·自动化
夜郎king4 小时前
Java实战:熵权法原理详解+房产价值评估系统设计(上)—— 构建客观多指标评价模型
java·开发语言·熵权法·熵权法java开发
WYH2874 小时前
C语言结构体变量和结构体指针详解:定义、访问、传参与易错点总结
c语言·开发语言·算法
AI人工智能+电脑小能手4 小时前
【大白话说Java面试题 第64题】【JVM篇】第24题:强引用、软引用、弱引用、虚引用分别是什么?
java·开发语言·jvm·面试
yujunl4 小时前
U9的UI插件开发Card功能区上客开的按钮不能正常显示
开发语言