Woovi Git 最佳实践

2025-06-07

Woovi Git 最佳实践

我们寻求遵循与 git 开发过程相关的良好实践文化。

下面您将看到一些最常用的做法。

Git 消息

请遵循以下 7 条规则:

  1. 用空行将头部与身体分开
  2. 标题限制为 50 个字符
  3. 不要用句号结束​​标题
  4. 在标题中使用祈使语气(例如:“Create”而不是“Created”)
  5. 正文在 72 个字符处换行
  6. 使用正文来解释什么、为什么以及如何

关于这些规则的非常好的文章:https://chris.beams.io/posts/git-commit/

Commitlint

我们的一些项目使用带有常规配置的commitlint

这意味着您需要使用以下格式创建提交消息:

type(subject): commit message
Enter fullscreen mode Exit fullscreen mode

请记住,这将进入变更日志,因此请创建与您的更改相关的简洁的提交消息,请记住您始终可以使用提交消息正文来说明有关更改的更多详细信息:

type(subject): commit message

some long commit body
Enter fullscreen mode Exit fullscreen mode

通常要查看可用的类型,请检查commitlint.config.js项目根目录下的文件,即type-enum密钥。

某些场景:
修复了 Woovi 上用户演进的一些 UI

style(user-evolution): fix the wrong color on feedback received chart
Enter fullscreen mode Exit fullscreen mode

修复了导致表单提交总是返回错误的一些错误代码:

fix(groups): add new Group form checking from the invalid return from mutation

Was checking for mutation result BlaBlaResult, instead of BlaResult.
Enter fullscreen mode Exit fullscreen mode

由于fix(subject)已经表明这是一个修复,因此您不需要以 开始提交消息fix blah

另一种情况是更新模式,尝试将更新模式作为单独的提交,并使用提交消息:

chore(schemas): update schemas
Enter fullscreen mode Exit fullscreen mode

分支命名

[kind-of-change]/[what-is-being-changed]尽可能尝试坚持格式。

例子:fix/user-name-during-loginimprovement/login-screenfeature/charge-customer-screen

拉取请求

要修改main或上的任何内容production,请务必先打开 PR。

合并 PR 需要 Woovi 开发人员的许多批准:

分支 批准
main 1✅
production 2✅

有用的 git 命令

从本地仓库中删除所有合并的分支

git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch -d
Enter fullscreen mode Exit fullscreen mode

或者,如果您只想在删除远程引用时删除它们

git config --global fetch.prune true
Enter fullscreen mode Exit fullscreen mode

删除所有不在远程的标签

git tag -l | xargs git tag -d
git fetch --tags
Enter fullscreen mode Exit fullscreen mode

自动更正 git

git config --global help.autocorrect 1
Enter fullscreen mode Exit fullscreen mode

从磁盘删除多个文件后再将其移除

git ls-files --deleted -z | xargs -0 git rm
Enter fullscreen mode Exit fullscreen mode

Git 别名

[alias]
    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    co = checkout
    ec = config --global -e
    cob = checkout -b
    cm = !git add -A && git commit -m
    st = status
Enter fullscreen mode Exit fullscreen mode

要将此别名添加到您的 git 命令行,请将其复制并粘贴到~/.gitconfig

应用一些现有提交引入的更改:git cherry-pick

主要思想是将提交从分支 A 转移到分支 B。

何时使用?
假设你提交到了错误的分支。将此提交复制并粘贴到正确分支的一个好方法是使用git cherry-pick

如何使用?
首先,git log在源分支中运行查看提交 sha1。然后,切换到目标分支并运行以下命令:

git cherry-pick commit_sha1
Enter fullscreen mode Exit fullscreen mode

所需提交的 sha1 字符串在哪里commit_sha1?如果没有任何冲突,则会应用更改。


Woovi是一家初创公司,致力于让购物者能够随时随地付款。为了实现这一目标,Woovi 为商家提供即时支付解决方案,方便他们接受订单。

如果您想与我们一起工作,我们正在招聘


照片由Roman Synkevych 🇺🇦Unsplash上拍摄

文章来源:https://dev.to/woovi/woovi-git-best-practices-1i0e
PREV
在 WordPress 中使用 Vue
NEXT
Woovi 为什么使用 MongoDB?