In the code below, all links that can reach the selected commit are retrieved.
using( Repository repo = new Repository( path_to_repo ) ) { foreach( Commit commit in repo.Commits ) { IEnumerable<Reference> refs = repo.Refs.ReachableFrom(new[] { commit }); } }
If you want to get only Tag s, the method provides an overload to help you with this.
using( Repository repo = new Repository( path_to_repo ) ) { var allTags = repo.Refs.Where(r => r.IsTag()).ToList(); foreach( Commit commit in repo.Commits ) { IEnumerable<Reference> refs = repo.Refs.ReachableFrom(allTags, new[] { commit }); } }
Note. . This code will retrieve all links that either directly indicate the selected commit or point to the ancestor of this commit. In this sense, it behaves similarly to the git rev-list command.
source share