Search code examples
gitlab-api

In Gitlab api how to find out list of distinct commit ids and commit description between two branches?


I have to find out the missed commits between master and a feature branch using gitlab ui rest services. What is the curl and syntax to get these details?


Solution

  • You can achieve this by using the Gitlab API

    GET /projects/:id/repository/compare
    

    More info at https://docs.gitlab.com/ee/api/repositories.html#compare-branches-tags-or-commits

    By executing the following

    curl -s --header "PRIVATE-TOKEN: <access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/compare?from=<branch_name_behind_in_commits>&to=<branch_name_ahead_in_commits>&straight=true" | jq '. | .commits[] | "\(.id) \(.message)"'
    

    You will get the commit ids and their messages, that are present to master_branch and not to feature_branch

    Notes:

    1. access_token, you need to provide this to the command if your repo is not publicly available
    2. project_id. this is the ID of the project to which you want to compare branches.

    enter image description here


    1. In the from field you should pass the branch that is behind in commits in comparison with the branch you specify in the to field