It can be read from the .git folder
String commitHash = Files.readString(Paths.get(".git", branch)).trim();