This write-up will explain the methods to display the commits between two commit hashes in Git.
How to List/Display Commits Between Two Commit Hashes in Git?
Different Git commands can be used to display the commits between two commit hashes, such as:
- “git log –oneline <commit-hash1>~…<commit-hash-2>”
- “git rev-list –ancestry-path <comit-hash1>~…<commit-hash-2>”
Method 1: List Commits Between Two Commit Hashes Using “git log –oneline” Command
To list commits between two commit hashes including the commit message, utilize the following command along with the desired commit hashes. For instance, we want to display the commits between the “60f911d” and “dc1157a” commit hashes:
Here, the “~” symbol is used to exclude the “60f911d” commit.
The below output displayed the commits between the specific commit ids:
Moreover, if you want only to view the commit id between the two specified commit hashes, use the “cut -d ” ” -f 1” option with the same command:
Method 2: List Commits Between Two Commit Hashes Using “git rev-list” Command
Type out the following command along with the “–ancestry-path” option and specify the commit hashes to view the commits between them:
The below image shows the full SHA-hash value of the commits between the specified commit ids:
We have explained the methods of listing the commits between two commit hashes in Git.
Conclusion
Various Git commands can be used to list the commits between two commit hashes, such as the “git log –oneline <commit-hash1>~…<commit-hash-2>” command displays the commits with commits messages and the “cut -d ” ” -f 1” option with the same command displays only the commit hashes. Moreover, the “git rev-list –ancestry-path <commit-hash1>~…<commit-hash-2>” command is used to display the full SHA hash of the commits between the specified commit ids. This write-up explained the methods to display the commits between two commit hashes in Git.