0

I am migrating from CVS to git. In CVS, I can use $Log$ in my comments section, and CVS will write comments at the point of $Log$. Is there an equivalent for this in git?

I have looked and seen the powerful command line and add-on tools available to me, and I'll wind up using those if there is no equivalent, but I am just wondering if an equivalent exists.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131

1 Answers1

1

Git doesn't support this be design, because you cannot update a file with commit info after committing, since git checksums the file first.

A workaround is to use attributes, using the "smudge" and "clean" filters and a post-commit hook. What these basically do is update the file with information once it is checked out, and remove the info before it is checked in.

My solution (written in Python) for the $Date$ an $Revision$ keywords (the latter are implemented as to make use of tags) is available on github. You should be able to expand that for $Log$.

However:

You should think really carefully if you want this, because this approach has potential problems;

  • It needs external programs.
  • You have to set a post-commit hook if you want to use it.
  • It might not be portable (I haven't tried it on ms-windows).
  • It might cause loops if you have both source code and compiled programs checked into the repo.

And last but not least, git commands like e.g. git log and git diff can give you much more information than a static log message.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • It works and will update to the latest date and revision after committed, but it doesn't work when other user do git pull. It didn't reflect the latest date and revision. Any solution to that? – hexacool Oct 22 '20 at 05:01
  • 1
    @hexacool When somebody pulls a repo, they won't get the post-commit hook, nor the smudge and clean filters. So it will not work for them. – Roland Smith Oct 22 '20 at 18:50