What command lists all commits that are ancestors of a specified commit but exclude commits that are ancestors of another specified commit?
Posted by RoseHrs
Last Updated: July 13, 2024
In Git, you can use the following command to list all commits that are ancestors of a specified commit while excluding commits that are ancestors of another specified commit:
git log [commit_sha1] ^[commit_sha2]
Here's a breakdown of the command: - Replace [commit_sha1] with the SHA-1 hash of the commit whose ancestors you want to include. - Replace [commit_sha2] with the SHA-1 hash of the commit whose ancestors you want to exclude. - The ^ symbol before [commit_sha2] indicates that you want to exclude those commits. For example, if you want to see all commits that are ancestors of commit abc123 but exclude those that are ancestors of def456, you would use:
git log abc123 ^def456
This command will show you a list of commits that are ancestors of abc123 but not ancestors of def456. If you also want to see the log in a simplified format, you can add the --oneline option:
git log --oneline abc123 ^def456
This will give you a more concise output.
Related Content