GIT:提交时有文件中的当前提交散列和最新标记 [英] GIT: Have current commit hash and latest tag in file on commit

查看:120
本文介绍了GIT:提交时有文件中的当前提交散列和最新标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是更多的知识问题:



我使用git进行版本控制,并将PHP CMS的文件发送到使用rsync的测试或生产站点。现在我想跟踪目前使用傻瓜和自动系统部署什么,我在想这个:



设置一个git钩子使用最新的标签添加/更新文本文件并提交散列。然后我可以很容易地查看提交。



我的问题是,在提交前,脚本将不知道提交哈希。有没有任何直接的方法来完成(或另一种方法来达到同样的目的)?



感谢您提前输入!

解决方案

好吧,我想我有一个ok解决方案:



< >有一个名为post-commit的git钩子,这里是我所做的:




  • 我把保存标签/哈希的文件放在。 gitignore(以避免下一次提交的不必要的更改)

  • 让提交后的挂钩更新版本文件。



挂钩文件的内容:

 #!/ bin / sh 
git describe --tags> version.txt

现在我确信每次提交后文件都是最新的,所以只要我在部署之前做了一个提交,我都设置好了。



注意:
讨厌的初学者的警告:使钩子文件可执行,如果没有,git会忽略该文件而不发出警告。



所有关于git钩子: http: //git-scm.com/book/en/Customizing-Git-Git-Hooks



所有关于.gitignore:http://git-scm.com/book/en/Git-Basics-Recording -Changes-to-the-Repository#忽略文件



干杯,



Martin


that's more of a know-how questions probably:

I'm versioning with git and send files for a PHP CMS to the test or production site using rsync. Now I'd like to keep track on what commit is currently deployed using a fool-proof and automated system, I was thinking about this:

Set up a git hook to add/update a text file with the latest tag and commit hash. Then I can easily look up the commit.

My problem is that at the time of pre-commit the script won't know the commit hash. Is there any straight-forward method to get that done (or another approach that comes to the same ends)?

Thanks for your input in advance!

解决方案

Alright, I think I got an ok-solution:

There is a git hook called post-commit and here is what I do:

  • I put the file holding the tag/hash on .gitignore (to avoid unnecessary changes on the next commit)
  • Let the post-commit hook update the version file.

Content of the hook file:

#!/bin/sh 
git describe --tags > version.txt 

Now I'm sure that file is up-to-date after each commit, so I'm all set as long as I do a commit before deploying.

Notes: Nasty beginner's caveat: make the hook file executable, git ignores the file without warning if it isn't.

All about git hooks: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

All about .gitignore: http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files

Cheers,

Martin

这篇关于GIT:提交时有文件中的当前提交散列和最新标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆