I read tons of articles saying this can’t and shouldn’t be done, I understand why Git doesn’t support it native and I also understand that I could use lots of other ways to work around it. All the work around solutions seemed just as much of a hack.
On checkout/pull/commit I want the last commit ID, user and commit message for a file added to the file in my local repository at a specific location. I deploy this scripts to a server and they do not get a version number, nor can I easily compile one. I want to know what version of the script our deployment packages placed on the server simply by browsing the scripts on the production server.
PVCS offered this for years with their $LOG: tag. In PVCS’s case it actually puts a running history of the file in places of the $LOG just before check-in. The file in the repository actually contains the changes checked into it. This makes the commit messages appear in diffs which is not terribly useful. This is one of the many reasons I get why GIT does not support this function. SVN had similar functionality.
I was excited when I originally found Git IDENT, hoping that it’s functionality could be used to achieve something similar but the $ID in Git (checksum of file) is not helpful in this case. I want an easy way to reference the commit in the repository and see which version of the file is deployed.
I first experimented with Git filters using clean/smudge and got most of the replacement functionality working. It didn’t work when I pulled in someone else’s changes. It wasn’t working on cloning a repository. Worst of all the log data I wanted wasn’t actually available on disk until after the commit completed which is also after the smudge filter runs. The smudge/clean turned out to work perfectly when doing diffs, but not so great to handle the insertion of the expanded data.
Git hooks filled the gap where smudge/clean couldn’t work. The post-commit and post-merge hooks fire after a pull/merge and also after a commit. I call the same scripts I made for the clean/smudge filters and apply the changes only to my local working tree. Clean takes care of removing this data before committing and the files in the remote repository stay clean!
Os programas com prefixo Tortoise possuem um conjunto de funcionalidades essencial para os sistemas de controle de versão. Há muitas complicações em usar Git no Windows e o programa TortoiseGit ajuda muito bem seus usuários.