简体   繁体   中英

What commits are missing from Master?

I can check what branches a specific commit has gone into by doing:

git branch --contains 469bcec

Is there anyway I can get what commits have not gone into a specific branch?

For example, is there anyway I can check what commits have not going into Master?

Thanks

这至少接近你想要的 - 不确定它是否完全匹配:

git log --pretty=oneline --all --not master

There is no way to specify "all commits in a repo regardless of label" (well, internally, there sort-of-is, that's how git fsck finds "dangling commit"s) but you would not want that anyway as it would find "temporary, non-branch" commits such as those in refs/stash and its reflog.

It's also not clear whether you want to include or exclude commits named via refs/remotes/ , for instance ("remote branches"), or those named via tags. However, in general, the way to do this is to start with talles' answer , which uses the .. syntax: EXC .. INC means the same thing as INC --not EXC , ie, all commits reachable starting from the "include" point INC , minus all commits starting from the "exclude" point EXC . If the include point is branch devel and the exclude point is master , this is a list of commits "on devel " that are not "on master ". (And you can omit either side to mean "use HEAD ", so ..master means "include HEAD , exclude master " which means "all commits on this branch that are not on master .)

Using the expanded form, it's possible to ask for all commits reachable from multiple starting "include" points, minus those reachable from an "exclude" point. So:

git log featureA featureB --not master

gets you everything on the two feature branches that is not in master .

If you want "local branches", though, there is direct way: git rev-list has a --branches argument. Using --branches means "all local branches". You can add = pattern to pick only branches matching some shell-style pattern, eg, --branches='feature*' to pick up branches featureA , featureB , and so on, but not branch devel .

Feed these to any command that uses git rev-list , including git log :

$ git log --oneline --graph --decorate --branches --not master

There are similar git rev-list arguments for tags and remotes, along with --glob , which allows you access to the complete reference name space. Providing --all (as in twalberg's answer ) means the same as --glob=* , ie, include every reference in the refs name space—which includes refs/stash , not always what you want.

(Also, one last syntactic trick: you can spell --not master with ^master . This is subtly different from using --not : --not flips a boolean flag that applies to all subsequent names, while a leading ^ applies only to its one item; so --not rel1 rel2 "means" the same thing as ^rel1 ^rel2 . Note that ^commit is very different from commit^ . Ah, git. :-) )

I don't know if you can do it for all your branches in one command (without scripting), but for specific ones you can do it:

git log master..mybranch

This lists all revisions present on mybranch that aren't on master .

You can also use multiple branches on the same command:

git log master..mybranch1 master..mybranch2

For the sake of simplicity you can also add the --oneline option and omit the current branch you are on (let's suppose you are on the master branch):

git log ..mybranch1 ..mybranch2 --oneline

Another way: Git 1.9/2.0 (Q1 2014) will include a new --exclude option with commit 10167eb :

People often wished a way to tell " git log --branches " (and " git log --remotes --not --branches ") to exclude some local branches from the expansion of " --branches " (similarly for " --tags ", " --all " and " --glob=<pattern> ").
Now they have one.

The git rev-parse and git rev-list now mention:

--exclude=<glob-pattern>::

Do not include refs matching ' <glob-pattern> ' that the next --all , --branches , --tags , --remotes , or --glob would otherwise consider.
Repetitions of this option accumulate exclusion patterns up to the next --all , --branches , --tags , --remotes , or --glob option (other options or arguments do not clear accumlated patterns).

The patterns given should not begin with refs/heads , refs/tags , or refs/remotes when applied to --branches , --tags , or --remotes , respectively, and they must begin with refs/ when applied to --glob or --all .
If a trailing ' /{asterisk} ' is intended, it must be given explicitly.

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