git configuration and replacement of gerrit default commit-msg hook


Git configuration specification

Configure username and email

In order to submit records for easy identification, configure the Chinese name, and configure the mailbox as gitlab registered mailbox

 git config --global "中文姓名"  
git config --global "[email protected]["

Example Configuration rule: name#工号 Example git config --global "张三#A00003" Configuration rule: Use the company's mailbox uniformly. Example git config --global "[email protected]"

Keep a line break in the warehouse with LF

 git config --global core.autocrlf input // 因为linux服务默认使用LF作为换行符格式

Reference: git core.autocrlf configuration instructions

Git Chinese path name is garbled

 git config --global gui.encoding utf-8  
git config --global core.quotepath false

Let git mergetool no longer generate annoying backup files ( *.orig )

 git config --global mergetool.keepBackup false

Make filenames case sensitive

 git config --global core.ignorecase false

Do not modify the file mode (file mode changes are not submitted to the warehouse)

 git config --add --global core.filemode false

When file renaming does not take effect (case insensitive), please use git mv to rename

 git mv lineConfig.js LineConfig.js

To facilitate your configuration, you can directly run the following script

# 配置用户名和邮件
# 为了提交记录便于识别,配置中文名,邮箱配置成gitlab注册邮箱
# 配置规则: name#工号  示例   git config --global "谭智军#A00015"  
# 配置规则: 统一使用公司的邮箱。示例 git config --global "[email protected]"  

read -p "请输入您的姓名和工号,示例为:王永林#A00514.输入后请按[enter]键结束。" USER_NAME
git config --global "$USER_NAME" 
echo "设置后 值为 "
git config
# TODO 符合正则 [\u4e00-\u9fa5]{2,}#[A-B]\d{5} 才可以继续输入

read -p "请输入您在gitlab上注册的公司邮箱,示例为:[email protected]输入后请按[enter]键结束。" USER_EMAIL
git config --global "$USER_EMAIL" 
echo "设置后 值为 "
git config

#保持仓库中以 LF 换行
git config --global core.autocrlf input
echo "git config --global core.autocrlf input"

git config --global gui.encoding utf-8   
git config --global core.quotepath false
echo "git config --global gui.encoding utf-8"
echo "git config --global core.quotepath false"

#让git mergetool不再生成烦人的备份文件(*.orig)
git config --global mergetool.keepBackup false
echo "git config --global mergetool.keepBackup false"

git config --global core.ignorecase false
echo "git config --global core.ignorecase false"

git config --add --global core.filemode false
echo "git config --add --global core.filemode false"

It is used as follows:


The first step: save to the specified system directory;

Step 2: Right-click in the directory and select [Git Bash Here] to enter the Git command line interface;

Step 3: Enter the following command

 chmod 777

./ // 执行git_config_default.sh脚本

An example of execution is as follows:



The first step: save to the specified system directory;

Step 2: Right-click in the directory and select [Enter Terminal] to enter the Git command line interface;

Step 3: Enter the following command

 chmod 777

An example is as follows:


Git commit specification


git commit Information is a basic interactive window, which can quickly determine the impact of submission, related design documents, and related defects bug Single, follow-up can also be traced to improve the project or team work.

git commit The standardization of information not only reflects the professional quality of development students, but also belongs to the company's process assets. Therefore, the specification design submitted by git commit is as follows.


In the commit submission specification, clarify the submission format

【Submission Type】

​ Clarify the purpose of a code commit. Either a new feature ( feat ), or a fix bug ( fix ), or a dependency, build, configuration upgrade, test code other etc. other ).

【Submission Instructions】

After clarifying the purpose of submission, we also need to look at the specific content. Use keywords to describe the submission details, and more clearly convey the value of the submission.

【Related Links】

​ 方便支持接口设计、 story设计、需求、 bug描述等不同类型代码提交的需求,我们同时支持JIRAconfluence link.

For ease of use, we adopt the Angular specification, as follows:


      提交说明 (必须):描述此次提交所修改的内容(长度限制2~100, 约定说明中不要包含"[]", 会影响校验规则)
      相关链接 (必须):Jira 链接或 Confluence 链接 
      提交类型:  提交说明  [相关链接] 
     feat:  git提交规范说明  []

Frequently Asked Questions about Specifications

问题1: story发布阶段没有jirajira编号的不知道如何填写, Jira

In response to this problem, we communicated with the development students, and we changed the mandatory requirement to fill in the jira number to a mandatory requirement to fill in the relevant link, so that in the story design stage can fill in story 200a7f3eb3e7a2691f1a1217cc88782f---address, you can fill in the checklist confluence address in the release stage.

Question 2: There are too few submission types, and I don't know how to choose. For example, in the following scenarios, modify ci , package the official version, adjust the code format, code refactoring, performance optimization, etc.

In response to this problem, we still insist on not adding new types, but modify the original refactor to other .

  • Reasons for not adding commit types

​ One reason In order to restrict the code integrity when submitting, we recommend a specific story function corresponding to one submission. It is not recommended that a function is submitted multiple times. If there are too many types, Then when I modify the code at will, I can have the corresponding type to choose, and there is no constraint on the integrity of the code. Another reason is that the simpler and easier to understand, everyone has their own understanding. For example, I modified a version of pom c68cb195bdae9cb85658a0191e36c438--- and repackaged it, but now the types are ci build , how to choose this scene, I believe some people will think it is ci , and some people will think it is build

  • How to choose the submission type

​ For code refactoring and performance optimization, these two scenarios have no type. From an iterative point of view, these two scenarios also belong to adding new functions or repairs bug , because when doing two tasks, it must be Corresponding story or jira need to be tracked. There may be some scenes that need special adjustment, but generally this kind of scene is low frequency, choose other , add the corresponding description, you can also understand that it is consistent with angular Those types submitted are now subtypes, just saying that this subtype is put in the description


This section mainly describes how to integrate the existing project commit-msg hook --- to verify the Commit information.初步想法是利用githooks来进行验证, git commit命令后, hook ,然后对Submitted commit information for format verification.


Git Hook is roughly divided into two types, one on the server and one on the local. Among them, the local hook is not managed by the version controller, which means that we cannot put the written hook script under .git/hooks , and then push it Go to the warehouse for your friends to download and use (unless you manually copy the hook file to the project's ./git/hooks directory)

After analyzing the gerrit code review platform, we have solved the problem that students need to manually execute the command to download commit-hooks . For students on how to solve this problem, please refer to the following:

gerrit how to replace the default commit-hook file

How to integrate our custom hook to check the submission information, and let the developers get the specification check we provide hooks without doing anything? At first, I encountered many problems. I have tried the command line and plug-in methods, but they have not solved this problem very well. It still needs to be executed manually by developers. In order to solve this problem well,

We first put it on the gerrit code review platform clone a project command:


## SSH方式
git clone "ssh://[email protected]:29418/open/icec-cloud-job" && scp -p -P 29418 [email protected]:hooks/commit-msg "icec-cloud-job/.git/hooks/"

## HTTP方式
git clone "http://[email protected]:8087/a/open/icec-cloud-job" && (cd "icec-cloud-job" && mkdir -p .git/hooks && curl -Lo `git rev-parse --git-dir`/hooks/commit-msg http://[email protected]:8087/tools/hooks/commit-msg; chmod +x `git rev-parse --git-dir`/hooks/commit-msg)

git clone "" && (cd "icec-cloud-job" && mkdir -p .git/hooks && curl -Lo `git rev-parse --git-dir`/hooks/commit-msg; chmod +x `git rev-parse --git-dir`/hooks/commit-msg)

It can be seen that the command is divided into two parts, one part is to execute clone code operation, and the other part is to execute download gerrit provide hooks operation, thus It can be seen that gerrit is provided with the default commit-hook file, we just need to replace it.

Based on the above analysis, we did the following steps


Note: The location of lib in the document is wrong. The real need to replace is the lib package in the screenshot. The replacement can be completed and restarted, and no initialization and other steps are required.


Tips (front-end development students pay attention)

git the process of submitting the specification for trial implementation, the front-end project seems to have integrated a husky plug-in, which covers the project .git/hooks . The project here is decided by SE to continue to use husky plugin or use our recommended method

1. If it is a project that has not yet clone , it is normal clone The project is fine, nothing else needs to be done, we have replaced gerrit commi-hook file, the verification file will be automatically cloned to the project's .git/hooks directory with the clone command.

2. If clone arrived at the local project before git submitted the specification for implementation, you need to manually execute the command to download commit-hook , the command is as follows

hook download command

 # 如果clone的项目是gerrit项目,则执行此命令
curl -Lo .git/hooks/commit-msg
# 如果clone的项目是gitlab项目,则执行此命令
curl -Lo .git/hooks/commit-msg

3. After execution, open the project .git/hooks commit-msg file in the directory, if you see the following information, it means the download has been successful commit-hook



Simulate a submission that does not conform to the specification. When the commit action is executed, it will prompt that it does not conform to the specification, and then output the corresponding submission specification in the console

  • Example 1: Simulated command line submission fails


  • Example 2: Simulation IDEA submission failed


阅读 3.3k


1.6k 声望
4.4k 粉丝
0 条评论


1.6k 声望
4.4k 粉丝