Giter Club home page Giter Club logo

git-vanity-hash's Introduction

git-vanity-hash

Overview

git-vanity-hash is a command line tool for creating commit hashes with a specific prefix. Hashes are computed on the cpu using all available cores.

FAQ

Question Answer
Is this a good idea? No
Will this break git tooling? Probably (see how it works)

Usage

git-vanity-hash <mode> [prefix]

mode
    find        Find and print hash (read-only)
    update      Find and update HEAD with found hash
    revert      Revert HEAD back to original commit

prefix
    A hexadecimal string the hash should start with

Examples

Find hash
$ git-vanity-hash find cafe
Found hash: cafe7f3302e66fef6428029563534ff2d8d0bc4f
Update HEAD
$ git-vanity-hash update cafe
Updated HEAD from 6af06aeb70482ba69e5c85225f8c4a0e98cbd942 to cafe7f3302e66fef6428029563534ff2d8d0bc4f
Revert HEAD
$ git-vanity-hash revert
Reverted HEAD from cafe7f3302e66fef6428029563534ff2d8d0bc4f to 6af06aeb70482ba69e5c85225f8c4a0e98cbd942
Full example
$ git init
Initialized empty Git repository in /Users/user/cool-project/.git/

$ git add README.md

$ git commit -m "Add readme"
[master (root-commit) 6af06ae] Add readme
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

$ PAGER=cat git log
commit 6af06aeb70482ba69e5c85225f8c4a0e98cbd942 (HEAD -> master)
Author: Petter Rasmussen <[email protected]>
Date:   Sun Feb 23 14:11:19 2020 +0100

    Add readme

$ git-vanity-hash update cafe
Updated HEAD from 6af06aeb70482ba69e5c85225f8c4a0e98cbd942 to cafe7f3302e66fef6428029563534ff2d8d0bc4f

$ PAGER=cat git log
commit cafe7f3302e66fef6428029563534ff2d8d0bc4f (HEAD -> master)
Author: Petter Rasmussen <[email protected]>
Date:   Sun Feb 23 14:11:19 2020 +0100

    Add readme

How it works

The commit object is read using git cat-file commit HEAD. An example how it looks:

tree bd2171194b1f31c586da1ee133a845810e303a23
parent 000000757d84e66644069f387f30f657faee4187
author Petter Rasmussen <[email protected]> 1582460250 +0100
committer Petter Rasmussen <[email protected]> 1582460640 +0100

Add README

A new vanity header and value is added. An example how it looks after the vanity headers is added:

tree bd2171194b1f31c586da1ee133a845810e303a23
parent 000000757d84e66644069f387f30f657faee4187
author Petter Rasmussen <[email protected]> 1582460250 +0100
committer Petter Rasmussen <[email protected]> 1582460640 +0100
vanity 7-16488

Add README

The string is hashed (see commit_info.rs for more details) and checked if it has the wanted prefix. The vanity value is increased until a matching hash prefix is found.

When a match is found the new commit object is written to the object database with git hash-object -t commit --stdin And then HEAD is changed to point to the new object with git update-ref HEAD <hash>

The vanity header will normally not show when using basic git commands, but can be seen using i.e. git cat-file commit HEAD. Note that the default git tools has support for extra headers, but there is no guarantee that this won't break 3rd party tools.

Similar projects

git-vanity-hash's People

Contributors

prasmussen avatar hoodie avatar

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.