0

I have a private git repository that I do all of my staging on before pushing it up to Github. I have the following template

/**
 *
 * @version ${commit}
 * @since ${initial_commit}
 */
public class Foo {

}

What I want is to have the ${initial_commit} to be replaced with the commit number when the file was added to the repo, and every time there is a change, change the ${commit} to the resulting commit number. Is there some way to accomplish this? I saw another post about using a post-commit hook, but my thinking is that, the commit number (or value/hash) is calculated based on the changes, but by changing the values in the post-commit hook when committing to the public repo, it would have a different number. Or am I mistaken?

Zymus
  • 1,673
  • 1
  • 18
  • 38
  • 1
    Yes, the way you describe it is impossible. See this previous question, there are some ideas that might help: http://stackoverflow.com/questions/3442874/in-git-how-can-i-write-the-current-commit-hash-to-a-file-in-the-same-commit – Thomas Stets Feb 13 '15 at 06:35
  • while it's not possible to have the actual commit hash in the fields, it would be possible to print the direct parent there (i.e. not `initial_commit` but `first_parent_commit` and not `commit` but `last_changed_after_commit`). You could use git filters for this: http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes. The article also shows how to write the last change date into your sources. – eckes Feb 13 '15 at 10:01

1 Answers1

0

You are correct. The hash refelcts the content of the commit. This makes it impossible to have the hash number anywhere in the commited data.

You could wirte a script which replaces initial_commit with a hash. This of course requires a new commit.

BetaRide
  • 16,207
  • 29
  • 99
  • 177