惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
T
Tenable Blog
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
WordPress大学
WordPress大学
Latest news
Latest news
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
C
Cisco Blogs
博客园 - 聂微东
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
小众软件
小众软件
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
Y
Y Combinator Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 最新话题
月光博客
月光博客
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
S
Security Affairs
P
Proofpoint News Feed
D
DataBreaches.Net
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG

Xinwei Xiong (cubxxw) - AI, Open Source & Nomad Blog

2026 June Thought Notes: The Pushing-Away Comes Be… | cubxxw Dissecting open-lovable: An App Generator That Tam… | cubxxw Ignite and Settle (Part 3): Anxious Attachment — W… | cubxxw Ignite and Settle (Part 2): Avoidant Attachment — … | cubxxw Ignite and Settle (Part 1): The Quality and Time o… | cubxxw The Super-Individual Stack: AI-Native Product Dire… | cubxxw Building a Production-Grade AI Agent System from S… | cubxxw Seen Clearly, Loved Deeply: Five Lenses on Love, a… | cubxxw Context Is Not Prompt: Why Context Engineering Is Becoming AI's New Foundation The Agent Engineering Map: Where Does That 98.4% o… | cubxxw April 2026 Thought Notes Agent Identity: From Locke to OpenClaw Maintaining Self-Worth in the Age of AI March 2026 Thought Notes Lhasa: Slow and Heavy Wandering & Growing: 2025-2026 Annual Review AI and Self-Identity: Who Am I in the AI Age February 2026 Thought Notes January 2026 Thought Notes December 2025 Thought Notes Japan Travel Notes — Learning to Be with Time Through Wood, Fire, and Gaps 2025 November Thought Notes October 2025 Thought Notes September 2025 Thought Notes 2025 August Thought Notes 2025 July Thought Notes 2025 June Thought Notes Metacognitive Transformation Review 2025 May Thought Notes 2025 April Thought Notes AI Recommendation Systems: How They Work NotebookLM: Google's AI Research Tool TDD for AI: Test-Driven Development Guide MarkItDown: Convert Documents to Markdown LangGraph: Stateful AI Agent Workflows LangChain: Open Source LLM Framework LLM/AI API Gateway Market Analysis & Startup Stack Recommendations Independent Developer in the AI Era: Open Source Deep Dive GPT Researcher: Open Source Deep Dive Jina AI: Multimodal Search & Embeddings 2025 March Thought Notes 2024 Annual Review Travel Footprints About Me Kubernetes Resources and Learning Path Summary LangChain: Building LLM Applications Large Language Models: How LLMs Work Open Source Resume Builders & Career Tips Troubleshooting Guide for OpenIM Navigating the Open Source Landscape Sora Ease Guide: Mastering Sora AI for Developers In 2023, I Was Wandering at the Edge of the World Exploring Sora Technology for Enthusiasts and Developers Combining GitHub and Google Workspace for Effective Project Management Brain-Friendly English Learning Strategies Flow State: Deep Focus and Happiness Guide GTD and the Quadrant Method Practice Go Directives & Automation Tools Deep Dive Concurrent Type Checking and Cross-Platform Development in Go Vector Database Learning OpenIM: Version Control & Testing Workflow Emerging Challenges and Trends in 2024 2023 Annual Summary Reflections and Aspirations GitOps & Kubernetes Deployment Strategies Deployment and Design of Management Backend and Monitoring Hugo Advanced Tutorial Kubernetes for Kustomize Learning OpenIM Use Harbor Build Enterprise Mirror Repositories Learn About Automated Testing Deep Dive into Kubernetes CNI, CRI, CSI Components Kubernetes Control Plane - Detailed Analysis of Kubelet Kubernetes Control Plane - Scheduler In-depth understanding of the components of Kubernetes Kube apisserver Deep Dive Into the Components of Kubernetes Etcd Kubernetes Port Config via Config Files OpenIM clustering design Kubernetes deploy concludes Open Source Business: From Community to Revenue The Art of Asking Questions in Open Source Communities Open Source Contribution Guidelines Cross Platform Compilation Github Actions Advanced Techniques Openim Devops Design GoReleaser: Automate your software releases Openim Multi Process Management About My Blog About My Hugo teaching Openkf Multi Architecture Image Prow Ecological Learning Openim Remote Work Culture Openim Offline Deployment Design Read Openim Project Sealos Openim Source Code Project Management From Theory to Practice Stage Growth of Open Source Use Auto Gpt Use Go Tools Dlv Participating in This Project Kubernetes an Article to Get Started Quickly Start Here | cubxxw 分类 · CATEGORIES
Advanced Githook Design
Xinwei Xiong · 2023-06-16 · via Xinwei Xiong (cubxxw) - AI, Open Source & Nomad Blog

[Xinwei Xiong Me] · June 16, 2023

9 min · 1872 words · EN |

What to do if the community is not standardized

As the COO of the OpenIM community, I am responsible for the communtiy and [GitHub configuration repository](https:/ /github.com/OpenIMSDK/.github) has been fully configured. And architect and design the entire OpenIM Makefile and CICD flows, as well as the log package, error codes, collaborative flows, contributor documents and community documents used by the entire OpenIM.

There will always be some problems at this time, even if you think your Contributor Document is very awesome. , very comprehensive, but still few people are willing to take the time to learn according to the specifications you wrote. This is a very big obstacle for me to build a top open source community, so I have this document today, and I will record it on GitHub Gists , provide instructions and links for pulling and using it, and maintain it regularly.

First, I provide the link to the clone:

git clone https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694

How to design

The first is for the basic functions, which are the well-known commit information and push information.

  • We can set the format of commit information
  • We can set the size of push
  • We provide the actions function
  • We provide the ability for Makefile to mark and clear Hook

I wrote a very comprehensive note when I was learning git, and shared it on GitHub, at this [🤖 link](https://github.com/cubxxw/awesome-cs-course/blob/master/Git /README.md), you can learn many advanced uses of git.

This article explains what git specifications are and how to find the appropriate CICD flow:

Unified format:

Unified format: git commit -m 'type(scope): description(#issue)'
```

We bring the email address `-s` when submitting the visa. This is a good habit.

````bash
git commit -s -m "..."
```

`git commit` art:

```
<type>[optional scope]: <description>
[optional text]
[optional footnote]
```

`git commit` submission type can be as follows:

1. `feat`: new function (feature)
2. `fix`: fix bug
3. `docs`: Documentation
4. `style`: format (changes that do not affect code operation)
5. `refactor`: Refactoring (that is, code changes that are not new features or bug fixes)
6. `test`: add test
7. `chore`: changes to the build process or auxiliary tools
8. `perf`: performance optimization
9. `revert`: rollback
10. `build`: build
11. `ci`: continuous integration

**⚠️ What should you pay attention to when using this Git hook? **

  • This git hook will stop you when you accidentally upload a large file and warn you that this is irreversible
  • This git hook will make you miserable when you have no way to control the commit format.

how to use

You can choose two ways to use Git hook:

  1. Directly as the pre-commit hook in the .git/hooks folder.
  2. Update your package.json with Husky:

Husky makes git hook easier and more convenient:

"husky": {
     "hooks": {
       "pre-commit": "sh ./some-path/pre-commit-prevent-large-files.sh"
     }
}

I designed this hook for the OpenIM community project, but after thinking about it, I decided to make it into a very convenient and high-end version Github Gist , why not use the features of Gist to record and save Git Hook, provide maintenance and download later, and also provide a communication platform, which is very perfect.

So my first step was to use GitHub Gist to provide a download channel, so that other projects in the future can also use the script to pull it directly with one click. to local.

Not only that, I designed a script for submission. We can use the script to push to the remote warehouse in a one-click and standardized way.

curl -L https://gist.githubusercontent.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694/raw/gitsync.sh |sh

**Default limit is 5MB maximum per file. If you feel that your commit is a special case, you can override this restriction using: **

GIT_FILE_SIZE_LIMIT=50000000 git commit -m "test: this commit is allowed file sizes up to 50MB"
#OR
git commit --no-verify

I don’t care about any specific files, just limiting the entire commit itself, which should at least make the developer thing twice before they might decide to git commit --no-verify

Reusable script for one-click installation:

curl -L https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694/raw/install.sh |bash

Contents

Note Click Raw in the upper right corner to enter the script file

Reusable installation script

#!/bin/sh
set -e
echo "Starting install script..."

SET_GIT_TEMPLATE_DIR=false
EXISTING_TEMPLATE=$(git config --global init.templateDir || echo "")
if [ -z "$EXISTING_TEMPLATE" ]; then
   echo "Creating a new global git template dir at ~/.git_template"
   mkdir ~/.git_template
   EXISTING_TEMPLATE="$(cd ~; pwd -P)/.git_template"
   SET_GIT_TEMPLATE_DIR=true
else
   EXISTING_TEMPLATE="$(eval cd $(dirname "$EXISTING_TEMPLATE"); pwd -P)/$(basename "$EXISTING_TEMPLATE")"
   echo "Using existing git template dir: $EXISTING_TEMPLATE"
fi

HOOKS_DIR="$EXISTING_TEMPLATE/hooks"
PRECOMMIT_HOOK="$HOOKS_DIR/pre-commit"
echo "Creating hooks dir if it doesn't already exist: $HOOKS_DIR"
mkdir -p "$HOOKS_DIR"
if [ -f "$PRECOMMIT_HOOK" ]; then
   echo "Cannot install hook as it's already defined: '$PRECOMMIT_HOOK'" >&2
   exit 1
fi

echo "Downloading the hook to $PRECOMMIT_HOOK"
curl -L https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694/raw/pre-commit -o "$PRECOMMIT_HOOK" 2> /dev/null
curl -L https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694/raw/commit-msg -o "$PRECOMMIT_HOOK" 2> /dev/null
curl -L https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694/raw/pre-push -o "$PRECOMMIT_HOOK" 2> /dev/null

echo "Making it executable"
chmod +x "$PRECOMMIT_HOOK"

if [ "$SET_GIT_TEMPLATE_DIR" = true ]; then
   echo "Defining ~/.git_template as the global git template dir"
  git config --global init.templateDir '~/.git_template'
fi

echo -e "\nDone! Any future git repo created in this user profile will contain the hook\n"


##################################################
GIT_PATH=$(git rev-parse --show-toplevel)
echo "===> Copying hooks to $GIT_PATH/.git/hooks/"
mv ~/.git_template/hooks/* $GIT_PATH/.git/hooks/

git commit 设置

pre-commit 文件:

#!/usr/bin/env bash

# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
# This is a pre-commit hook that ensures attempts to commit files that are
# are larger than $limit to your _local_ repo fail, with a helpful error message.

# You can override the default limit of 2MB by supplying the environment variable:
# GIT_FILE_SIZE_LIMIT=50000000 git commit -m "test: this commit is allowed file sizes up to 50MB"
#
# ==============================================================================


YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"

printMessage() {
   printf "${YELLOW}OpenIM : $1${ENDCOLOR}\n"
}

printSuccess() {
   printf "${GREEN}OpenIM : $1${ENDCOLOR}\n"
}

printError() {
   printf "${RED}OpenIM : $1${ENDCOLOR}\n"
}

printMessage "Running local OpenIM pre-commit hook."

# flutter format .
# https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694
# TODO! GIT_FILE_SIZE_LIMIT=50000000 git commit -m "test: this commit is allowed file sizes up to 50MB"
# Maximum file size limit in bytes
limit=${GIT_FILE_SIZE_LIMIT:-2000000} # Default 2MB
limitInMB=$(( $limit / 1000000 ))

function file_too_large(){
	filename=$0
	filesize=$(( $1 / 2**20 ))

	cat <<HEREDOC

	File $filename is $filesize MB, which is larger than github's maximum
        file size (2 MB). We will not be able to push this file to GitHub.
	Commit aborted

HEREDOC
    git status

}

# Move to the repo root so git files paths make sense
repo_root=$( git rev-parse --show-toplevel )
cd $repo_root

empty_tree=$( git hash-object -t tree /dev/null )

if git rev-parse --verify HEAD > /dev/null 2>&1
then
	against=HEAD
else
	against="$empty_tree"
fi

# Set split so that for loop below can handle spaces in file names by splitting on line breaks
IFS='
'

shouldFail=false
for file in $( git diff-index --cached --name-only $against ); do
	file_size=$(([ ! -f $file ] && echo 0) || (ls -la $file | awk '{ print $5 }'))
	if [ "$file_size" -gt  "$limit" ]; then
	    printError "File $file is $(( $file_size / 10**6 )) MB, which is larger than our configured limit of $limitInMB MB"
        shouldFail=true
	fi
done

if $shouldFail
then
    printMessage "If you really need to commit this file, you can override the size limit by setting the GIT_FILE_SIZE_LIMIT environment variable, e.g. GIT_FILE_SIZE_LIMIT=42000000 for 42MB. Or, commit with the --no-verify switch to skip the check entirely."
	  printError "Commit aborted"
    exit 1;
fi

commit-msg

#!/usr/bin/env bash

# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
#
# Store this file as .git/hooks/commit-msg in your repository in order to
# enforce checking for proper commit message format before actual commits.
# You may need to make the script executable by 'chmod +x .git/hooks/commit-msg'.

# commit-msg use go-gitlint tool, install go-gitlint via `go get github.com/llorllale/go-gitlint/cmd/go-gitlint`
# go-gitlint --msg-file="$1"

# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message.  The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit.  The hook is allowed to edit the commit message file.

YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"

printMessage() {
   printf "${YELLOW}OpenIM : $1${ENDCOLOR}\n"
}

printSuccess() {
   printf "${GREEN}OpenIM : $1${ENDCOLOR}\n"
}

printError() {
   printf "${RED}OpenIM : $1${ENDCOLOR}\n"
}

printMessage "Running the OpenIM commit-msg hook."

# This example catches duplicate Signed-off-by lines.

test "" = "$(grep '^Signed-off-by: ' "$1" |
	 sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" || {
	echo >&2 Duplicate Signed-off-by lines.
	exit 1
}

./tools/go-gitlint \
	 --msg-file=$1 \
	 --subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \
    --subject-maxlen=150 \
    --subject-minlen=10 \
    --body-regex=".*" \
    --max-parents=1

if [ $? -ne 0 ]
then
    printError "Please fix your commit message to match OpenIM coding standards"
    printError "https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694"
    exit 1
fi

push

#!/usr/bin/env bash

YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"

printMessage() {
   printf "${YELLOW}OpenIM : $1${ENDCOLOR}\n"
}

printSuccess() {
   printf "${GREEN}OpenIM : $1${ENDCOLOR}\n"
}

printError() {
   printf "${RED}OpenIM : $1${ENDCOLOR}\n"
}

printMessage "Running local OpenIM pre-push hook."

if [[ `git status --porcelain` ]]; then
  printError "This script needs to run against committed code only. Please commit or stash you changes."
  exit 1
fi

#
#printMessage "Running the Flutter analyzer"
#flutter analyze
#
#if [ $? -ne 0 ]; then
#  printError "Flutter analyzer error"
#  exit 1
#fi
#
#printMessage "Finished running the Flutter analyzer"

actions

git-warning.yml file:

# This workflow will check for large files being added in PRs
# and label the PR if one is found that exceeds the configured limit.
#
# For more information, see: https://github.com/marketplace/actions/lfs-warning

name: Large file size warning

on: 
  pull_request:
    # Ignore some files to avoid consuming Actions minutes unnecessarily 
    # for file types we're fairly confident we'll never need to worry about
    paths-ignore: 
      - '**.config'
      - '**.cs'
      - '**.cshtml'
      - '**.cs'
      - '**.csproj'
      - '**.cmd'
      - '**.dockerignore'
      - '**.gitignore'
      - '**.graphql'
      - '**.jsx?'
      - '**.md'
      - '**.props'
      - '**.ps1'
      - '**.scss'
      - '**.sh'
      - '**.sln'
      - '**.tsx?'
      - '**.yml'
      - '**/appsettings.*.json'
      - '**/Dockerfile'
      
jobs:
  run-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actionsdesk/lfs-warning@v2.0
      with:
        #token: ${{ secrets.GITHUB_TOKEN }} # Optional
        filesizelimit: '5242880' # 5MB

Once embedded in the Makefile, the whole logic is simpler:

# Copy githook scripts when execute makefile
COPY_GITHOOK:=$(shell cp -f script/githooks/* .git/hooks/; chmod +x .git/hooks/*)