git

Predict git commit id and commit a file which contains that commit id


How to do something like this:

  1. Create a with following content:

    $ cat testfile.txt
    This file will be committed with this id: 83b90a07620ef578450c40a6d38bacc42de7ad2d

  2. Commit testfile.txt
    $ git add testfile.txt
    $ git commit -m 'Thank you'

  3. Execute git log to verify predicted commit id:
    $ git log
    commit 83b90a07620ef578450c40a6d38bacc42de7ad2d
    Author: rohit01 <*@gmail.com>
    Date: Fri Feb 21 23:46:52 2014 +0530

Basically, predict the next git commit id and commit a file which contains that commit id.


Solution

  • That is cryptographically impossible.

    The git commit ID is an SHA1 hash of the contents of the commit.
    Any change you make in the commit will also affect the ID.