Injecting current git commit id into Java webapp

后端 未结 6 1214
抹茶落季
抹茶落季 2020-12-08 16:14

We have a git repository which contains source for a few related Java WARs and JARs. It would be nice if the Java code could somehow:

System.err.println(\"I          


        
6条回答
  •  青春惊慌失措
    2020-12-08 16:33

    You can get the last commit SHA with

    git rev-parse HEAD
    

    but it's generally a lot more useful to use

    git describe
    

    which will give you something that looks like this:

    v0.7.0-185-g83e38c7
    

    This works if you have tags - it will tell you how many commits from the last valid tag your current checkout is at plus a partial SHA for that commit, so you can use it to base a checkout off of later. You can use this identifier just like a SHA in most circumstances, but it's much more human readable.

提交回复
热议问题