I have a script bumping the version and making a commit with the bump and tagging it. The issue I am having is making sure develop gets fetched from remote then merged into feature branch to insure no conflicts during the PR merge.
How do I check that the feature and develop are
in sync
merged?
The git branch
command will show you branches that are merged, or are not merged. For instance, if you are on branch main
and branch side
was merged in at some point, but another branch ahead
has not yet been merged:
$ git branch --merged
* main
side
$ git branch --no-merged
ahead
$
It's possible (but somewhat painful) to use this to check. But if you just want to test one specific pair of branches (or indeed any specific pair of commits), the "is / is-not merged" quality is simply whether one is an ancestor of another, in terms of the commit graph.
The git merge-base
command has a mode in which it performs this test, for two specific commits (which you may specify in any form listed in the gitrevisions
documentation ):
$ if git merge-base --is-ancestor side main; then
> echo side is merged into main
> fi
side is merged into main
$
The test that git branch --merged
uses (for each branch, comparing it to the current branch) is the same as the test git merge-base --is-ancestor
uses, ie, the SHA-1 that the first commit (here side^{commit}
) is an ancestor of the current branch's tip commit. (A commit is considered an ancestor of itself, so you always get your own current branch from git branch --merged
. Assuming of course that you are on a branch in the first place—if you're in "detached HEAD" state, the list of all named branches does not include your detached HEAD.)
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.