I want to get all commit hash IDs of a master branch. Using the following command however only the latest commit id matches with the result. Old commit hash IDs don't belong to the master branch. Is there any other way to get commit hash IDs only belong to the master branch?
git rev-parse origin/master --all
CodePudding user response:
You can get just the hashes for a particular branch (e.g. master
) by running:
git log --pretty=%H master
CodePudding user response:
A "branch" in Git only points to a (single!) commit and is moved forward automatically when new commits are made. A commit can point to 0, 1, 2 or even more parent commits. A commit is said to be "on a branch" if it is reachable from the tip or head of the branch. This means that once a branch is merged into another branch, it becomes part of that branch.
To get a list of all commit ids of a branch, you can use git rev-list branchname
. Of course, this will also include commits that were merged ino from other branches. If you always merge in the same direction, you might say that only the first parent of each commit is important and relevant to you. In that case, you can filter the revision list to show only commits reachable through the first parent commit. To do so, specify the --first-parent
flag to above command.