I'm looking for exact command to list all the commits from all existing branches that are not merged into my branch (including from remote branches that was fetched) that are based on the tip of my staging branch.
git log --all --remotes
I use this to list all of the branches.
How do I exclude the once that I already have in the staging branch?
Use git log --branches --remotes ^staging
, or equivalently, git log ^staging --branches --remotes
.
You can use --all
if you mean all references (including tags, notes, refs/stash
, etc), but you specifically said branches and remote-tracking names, for which --branches
and --remotes
produce the correct match. Note that --branches
and --remotes
may be followed by =<pattern>
to match specific name patterns.
The trick here is that the negation syntax ( ^X
, or --not
followed by X
) tells the revision-walk code to exclude the commit named X
and any commit reachable from X
. Positive references give git log
places to start; negative references give git log
places to stop; and git log
then loops over a priority queue that contains commits that are yet to be visited. So, initially, the queue looks at (contains hash IDs of) all branch tips and all remote-tracking-name tips, in some order. Git visits the first such commit, unless it's excluded, ie, is at the tip of staging
or reachable from the tip of staging
. Git puts that commit's parent into the queue, then visits the next commit in the queue (unless it's excluded, as before).
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.