简体   繁体   中英

GitLab API How to find branch name for specific commit

I'm trying to find connection between tag and branch name. Using this:

GET v4/projects/:id/repository/tags?page=1&per_page=1

I get last tag and commit id. I need to find branch name with specific commit. How to get branch with specific commit id? I've tried "

GET v4/projects/:id/repository/commits/:short_id - but there isn't branch name in commit

v4/projects/id:/repository/branches?short_id="specific_id - returns all branches:(

All this because I need to pull local and then push to remote specific TAG

let's say I have 3 branches R_1.0, R_2.0 and R_3.0. Someone pushed new TAG 3.0. I need to find commit which is connected to this TAG and then BRANCH name...

There may not be one. A tag can name a commit that is not reachable by any branch name.

... because I need to pull this branch to local repository and then push to remote repository. It's all about pushing TAGs between two remotes repositories...

If you simply want to get the tag $T and its tagged commit from remote $r1 to remote $r2, via your local repository, you need not go through all this kind of craziness. Just do:

die() {
    echo "fatal: $@"
    exit 1
}
# e.g., r1=origin and r2=upstream, T=v1.2

# obtain the specific tagged commit and its history, using the
# same tag name locally, from remote r1
git fetch $r1 refs/tags/$T:refs/tags/$T || die "fetch from $r1 failed"

# then send that commit and the tag name to remote r2
git push $r2 refs/tags/$T:refs/tags/$T || die "push to $r2 failed"

(Note that the above script is not tested.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM