goland git 钩子 自动生成swagger

本文介绍了如何使用 Git 的 pre-commit 钩子来检查即将提交的文件是否包含非 ASCII 字符,以确保跨平台兼容性。同时,提到了利用 gfswagger 工具自动生成 Swagger 文档,并自动添加到 Git。这个过程有助于维护代码库的整洁性和标准化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

commit钩子:

.git/hooks/pre-commit

#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2
gf swagger -pack
git add .

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
	# Note that the use of brackets around a tr range is ok here, (it's
	# even required, for portability to Solaris 10's /usr/bin/tr), since
	# the square bracket bytes happen to fall in the designated range.
	test $(git diff --cached --name-only --diff-filter=A -z $against |
	  LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
	cat <<\EOF
Error: Attempt to add a non-ASCII file name.

This can cause problems if you want to work with people on other platforms.

To be portable it is advisable to rename the file.

If you know what you are doing you can disable this check using:

  git config hooks.allownonascii true
EOF
	exit 1
fi

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --

goframe自动生成swagger

gf swagger -pack
git add .

其他是默认脚本的

### 如何在 Goland IDE 中设置和配置 Git 版本控制 #### 安装并验证Git 为了确保可以在Goland中正常使用Git,需确认计算机上已安装Git。可以通过命令行工具运行`git --version`来检验是否成功安装以及查看当前版本。 #### 设置Git路径 进入Goland后,通过菜单栏选择 `File | Settings`(Windows/Linux) 或者 `Goland | Preferences...`(macOS),导航至 `Version Control | Git` 节点。在此处指定Git的可执行文件位置;如果系统已经正确设置了环境变量,则通常无需手动更改此选项[^2]。 #### 关联远程仓库与本地项目 当首次克隆一个新项目时,可以利用内置终端或VCS菜单下的`Checkout from Version Control -> Git` 功能完成操作。输入相应的GitHub地址以及其他必要参数即可把远端代码库复制到本地环境中[^3]。 #### 使用Goland管理Git流程 一旦关联好了本地工程同其对应的线上资源库之后,就可以借助于图形界面轻松地跟踪变更、提交改动、推送更新等常规任务了。具体来说: - **查看差异**:右键点击某个特定文件或者整个包名,选取`Git->Compare with Branch` 来对比不同分支间的区别; - **阶段化修改**:选中要加入下次提交的内容项,按下快捷键`Alt + Shift + A` (Mac 上为`Cmd + Shift + A`) 打开Add to VCS对话框,亦或是直接拖拽变动过的条目放入上方绿色区域实现相同效果; - **创建提交记录**:填写描述性的日志信息后,按住`Ctrl + K `(Mac 用户则是`Cmd + K`)触发Commit动作,这会将所有处于Staging Area内的变化永久保存下来; - **同步最新进展**:最后别忘了定期执行Pull/Fetch/Push以保持本地副本始终是最新的状态[^1]。 ```bash # 这里展示一些常用的Git命令作为补充说明 $ git status # 查看工作树状态 $ git diff # 显示自上次提交以来所做的更改 $ git log # 浏览历史提交列表 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nickdlk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值