Skip to content

Instantly share code, notes, and snippets.

@stufield
Last active December 12, 2020 19:08
Show Gist options
  • Save stufield/86483ea41dbbf9a25a9f77b5bfbee42a to your computer and use it in GitHub Desktop.
Save stufield/86483ea41dbbf9a25a9f77b5bfbee42a to your computer and use it in GitHub Desktop.
Git Keyword Expansion like SVN
# set up filters
git init
git config filter.kwd.clean ./filter_clean
git config filter.kwd.smudge ./filter_smudge
echo "*.txt ident" > .gitattributes
echo "*.txt filter=kwd" >> .gitattributes
git add -A
rm test.txt
git checkout test.txt
head test.txt
# --------------------
# Revision Info
# --------------------
# $Id$
# $Author$
# $Date$
###################################
# --------------------
# Revision Info
# --------------------
# $Id: dac9e60907658dff686543f0efb1e878a2a39c96 $
# $Author: Stu Field $
# $Date: Tue Dec 13 11:22:28 2016 -0700 $
###################################
#!/bin/bash
# --------------------------------------------
# This is run when files are staged; putting things
# back the way they are in the repository
# --------------------------------------------
sed -e "s/[$]Date:.*[$]/\$Date\$/" -e "s/[$]Author:.*[$]/\$Author\$/"
#!/bin/bash
# --------------------------------------------
# This is run on a checkout from a branch/repository
# it replaces the words "Date" and "Author" with appropriate substitutions
# --------------------------------------------
curdate=`git log --pretty=format:"%ad" -1`
aut=`git log --pretty=format:"%an" -1`
sed -e "s/[$]Date[$]/\$Date: $curdate \$/" -e "s/[$]Author[$]/\$Author: $aut \$/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment