乐闻世界logo
搜索文章和话题

How do I get the commit id of the head of master in git?

1个答案

1

In Git, to retrieve the commit ID of the master branch head (also known as commit hash), you can use the following command:

bash
git 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:

shell
4a5e6bd8fcae8b8afed8e9b20d84a3cce9e72a5f

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:

bash
git 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 回复

你的答案