我開始我的版本提交使用Git標籤-a v2.3.4 -m「一些信息」 ,這樣我可以標我的軟件版本與版本數字(例如2.3.4)編程(JAVA)獲取最後的Git標籤放置版本信息軟件
我想在軟件中有一個「約」菜單項,用戶可以顯示它們正在運行的版本。
有沒有辦法做到這一點(最好在Java中),以便我的應用程序可以「知道」其在git中的版本標籤?
我開始我的版本提交使用Git標籤-a v2.3.4 -m「一些信息」 ,這樣我可以標我的軟件版本與版本數字(例如2.3.4)編程(JAVA)獲取最後的Git標籤放置版本信息軟件
我想在軟件中有一個「約」菜單項,用戶可以顯示它們正在運行的版本。
有沒有辦法做到這一點(最好在Java中),以便我的應用程序可以「知道」其在git中的版本標籤?
如果你有你的回購本地:
import java.io.*;
public class HelloWorld
{
public static void main(String []args) throws IOException
{
System.out.println("Hello World");
String command = "git describe --abbrev=0 --tags";
Process p = Runtime.getRuntime().exec(command);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
String text = command + "\n";
System.out.println(text);
while ((line = input.readLine()) != null)
{
text += line;
System.out.println("Line: " + line);
}
}
}
也許與https://www.tutorialspoint.com/compile_java8_online.php
檢查,如果你有你在Github上回購:
https://api.github.com/repos/YOURNAME/YOURREPO/tags
例如:
https://api.github.com/repos/git/git/tags
這將爲您帶來最新的30個Git回購標籤。
你的意思是在你的構建腳本或實時應用程序中有這個嗎?前者會容易得多 - 只需將其設置爲構建參數即可。 –