- Git Version Control Cookbook
- Aske Olsson Rasmus Voss
- 360字
- 2021-12-08 12:33:50
Templates
In this example, we will see how to create a template commit message that will be displayed in the editor when creating a commit. The template is only for the local user and not distributed with the repository in general.
Getting ready
In this example, we will use the example repository from Chapter 1, Navigating Git:
$ git clone https://github.com/dvaske/data-model.git $ cd data-model
We'll use the following code as a commit message template for commit messages:
Short description of commit Longer explanation of the motivation for the change Fixes-Bug: Enter bug-id or delete line Implements-Requirement: Enter requirement-id or delete line
Save the commit message template in $HOME/.gitcommitmsg.txt
. The filename isn't fixed and you can choose a filename of your liking.
How to do it...
To let Git know about our new commit message template, we can set the configuration variable commit.template
to point at the file we just created with that template; we'll do it globally so it is applicable to all our repositories:
$ git config --global commit.template $HOME/.gitcommitmsg.txt
Now, we can try to change a file, add it, and create a commit. This will bring up our preferred editor with the commit message template preloaded:
$ git commit Short description of commit Longer explanation of the motivation for the change Fixes-Bug: Enter bug-id or delete line Implements-Requirement: Enter requirement-id or delete line # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: another-file.txt # ~ ~ "\.git/COMMIT_EDITMSG" 13 lines, 396 characters
We can now edit the message according to our commit and save to complete the commit.
How it works...
When commit.template
is set, Git simply uses the content of the template file as a starting point for all commit messages. This is quite convenient if you have a commit-message policy as it greatly increases the chances of the policy being followed. You can even have different templates tied to different repositories, since you can just set the configuration at the local level.
- C++程序設計教程
- 數字媒體應用教程
- Python數據可視化:基于Bokeh的可視化繪圖
- Programming ArcGIS 10.1 with Python Cookbook
- 算法精粹:經典計算機科學問題的Python實現
- AngularJS深度剖析與最佳實踐
- Java:High-Performance Apps with Java 9
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- 深入解析Java編譯器:源碼剖析與實例詳解
- scikit-learn Cookbook(Second Edition)
- Node.js實戰:分布式系統中的后端服務開發
- Java Web開發教程:基于Struts2+Hibernate+Spring
- 從零開始學UI設計·基礎篇
- MySQL數據庫教程(視頻指導版)
- Python全棧開發:數據分析