In Git, to retrieve the commit ID of the master branch head (also known as commit hash), you can use the following command:
bashgit rev-parse master
This command outputs the full hash of the latest commit on the master branch. For example, after executing this command, you might see the following output:
shell4a5e6bd8fcae8b8afed8e9b20d84a3cce9e72a5f
This string represents the commit hash at the head of the master branch.
Additionally, if you are on the master branch, you can use HEAD instead of master, as shown below:
bashgit rev-parse HEAD
This will also retrieve the latest commit ID of the current branch.
Using this approach enables you to conveniently retrieve and utilize the latest commit ID in scripts or automated workflows, such as for version tagging or reverting to a specific commit.
2024年6月29日 12:07 回复