Does Git have the feature that subversion had keyword substitution or something like that?

0

When I worked with cvs and Subversion I remember a feature where we put some notes in the files and every time we did a commit that data was updated. In general the data referred to the date, author and commit number. It was something like the example below

/*
 *   $Author: joazinho $
 *   $Rev: 153 $
 *   $LastChangedDate: 2016-04-15 17:32:15 -0300 (Fri, 15 Apr 2016) $
 */

In Git something similar for me to get the branch / tag, hash or etc ... that is native.

    
asked by anonymous 13.12.2017 / 14:19

1 answer

2

Directly you have not. But you can do scripts to do this for you.

It provides attributes that can be used in your script .

Example:

MYVERSION = '1.090'
## Call script to do updateVersion from .git/hooks/pre-commit
def updateVersion
  # We add 1 because the next commit is probably one more - though this is a race
  commits = %x[git log #{$0} | grep '^commit ' | wc -l].to_i + 1
  vers = "1.%0.3d" % commits

  t = File.read($0)
  t.gsub!(/^MYVERSION = '(.*)'$/, "MYVERSION = '#{vers}'")
  bak = $0+'.bak'
  File.open(bak,'w') { |f| f.puts t }
  perm = File.stat($0).mode & 0xfff
  File.rename(bak,$0)
  File.chmod(perm,$0)
  exit
end

Font .

More examples .

  

The whole notion of keyword substitution is just totally idiotic. It's trivial to "outside" the current content tracking, if you want to have it when doing release tar-balls etc.

     

- Linus Tovards

    
13.12.2017 / 14:28