Giter Club home page Giter Club logo

git-emojis-hook's Introduction

Git emojis hook

A simple git hook to provide strong guidelines for commit message with emojis.

The commit message rules are the ones from Angular. I just augmented them by substituting their textual types with emojis. So it should look like this:

๐Ÿš‘ (authentication): remove buggy function that allowed to login w/o passwd

You'll notice another slight change from Angular's rules: I added a space between type and (scope). It is indeed visually more pleasant after the emojis.

Emojis are actual unicode emojis and not markdown emojis like :fire:. So it will work virtually everywhere as long as unicode is supported.

There are two hooks, one that makes the actual substitution and another one that prints the git commit message helper in the editor.

Syntax

Here are the types, their respective codes and the corresponding emojis:

  • revert: :revert: โ€ข โณ
  • build: :build: โ€ข ๐Ÿ“ฆ
  • ci: :ci: โ€ข ๐Ÿค–
  • docs: :docs: โ€ข ๐Ÿ“–
  • feat: :feat: โ€ข ๐ŸŒŸ
  • fix: :fix: โ€ข ๐Ÿš‘
  • perf: :perf: โ€ข โšก
  • refactor: :refactor: โ€ข ๐Ÿšง
  • style: :style: โ€ข ๐Ÿ’„
  • test: :test: โ€ข โœ…

In addition to these, I added :tada: ๐ŸŽ‰ that's often used for the first commit!

How to use

For each project, add the two files in in the .git/hooks directory.

At the root of your git project, this one-liner can set up it all:

cd .git/hooks/ && curl -O https://raw.githubusercontent.com/Buzut/git-emojis-hook/master/commit-msg && curl -O https://raw.githubusercontent.com/Buzut/git-emojis-hook/master/prepare-commit-msg && chmod +x * || exit 0

Also, it might be handy to place the two files in a directory within your home and add a bash alias to automate the deploy.

For exemple, in your home diretory, you could organize things like this:

.gitemojis/
    commit-msg
    prepare-commit-msg

And in your .bash_profile or .bashrc

alias emogitify='cp ~/.gitemojis/* .git/hooks/'

Now, when in a project directory, emogitify will add the git-emojis' hooks.

Integrate to your projects

Unfortunately, hooks aren't part of a project and therefore, they cannot be commited with the project's files. Nevertheless, you can include the one-liner introduced above into your project's init script. For instance, with JavaScript's npm package manager you could do it like so:

{
  "name": "project-name",
  "version": "1.0.0",
  "description": "The next big thing",
  "scripts": {
    "prepare": "test -d .git && cd .git/hooks/ && curl -O https://raw.githubusercontent.com/Buzut/git-emojis-hook/master/commit-msg && curl -O https://raw.githubusercontent.com/Buzut/git-emojis-hook/master/prepare-commit-msg && chmod +x *"
  },
  "dependencies": {โ€ฆ},
  "devDependencies": {โ€ฆ}
}

prepare will then trigger on npm install and if there is a .git directory and the hooks will be installed automatically.

Based on Angular's commit message guidelines

Angular enforces succint and yet very clear guidelines for their commit messages. Let's have a look at the rules. The following is directly copied from their repo.

We have very precise rules over how our git commit messages can be formatted. This leads to more readable messages that are easy to follow when looking through the project history. But also, we use the git commit messages to generate the Angular change log.

Commit Message Format

Each commit message consists of a header, a body and a footer. The header has a special format that includes a type, a scope and a subject:

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

The header is mandatory and the scope of the header is optional.

Any line of the commit message cannot be longer 100 characters! This allows the message to be easier to read on GitHub as well as in various git tools.

The footer should contain a closing reference to an issue if any.

Samples: (even more samples)

docs(changelog): update changelog to beta.5
fix(release): need to depend on latest rxjs and zone.js

The version in our package.json gets copied to the one we publish, and users need the latest of these.

Revert

If the commit reverts a previous commit, it should begin with revert: , followed by the header of the reverted commit. In the body it should say: This reverts commit <hash>., where the hash is the SHA of the commit being reverted.

Type

Must be one of the following:

  • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

Scope

The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages.

git-emojis-hook's People

Contributors

buzut avatar exilko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

git-emojis-hook's Issues

.git is a file not a directory

Hey !

your git hooks seem really great, however when I try to copy the two files on '.git/hooks', It appears that .git is only a file.

Should we create a /.git/hooks/ folder ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.