feat-123我注意到当我在一个只有几个提交的分支(我们称之为)上时,显示了我从( )git log分支的分支的整个历史。develop有没有办法只显示日志的feat-123创建点?
3 回答
如果您知道它feat-123是从 分支出来的develop,则可以使用双点..语法将输出限制为仅那些不在 中git log的提交:feat-123develop
git log --oneline --graph develop..feat-123
要了解有关双点和其他有用的提交过滤语法的更多信息,请参阅
- 修订选择 -来自**免费在线 Pro Git 书籍的提交范围。
- Git Revisions -从官方 Linux Kernel Git 文档中指定范围。
There's no shorthand for "find any point where history rejoins", so you have to use something like what Cupcake and D4NI3LS suggested: explicitly stop logging at-or-before such a point.
There is, however, a way to automate this. It can be encapsulated in a "one line" shell script:
git log HEAD --not $(
git for-each-ref --format='%(refname:short)' refs/heads/ |
grep -v "^$(git symbolic-ref -q --short HEAD)$"
) "$@"
How this works:
- The innermost bit,
git symbolic-ref -q --short HEAD, prints the current branch name, or nothing at all if you are not on a branch ("detached HEAD" state). - We turn this into a grep pattern by adding
^(anchor at start-of-line) and$(anchor at end). - We use that to remove the current branch (if any) from
git for-each-refoutput. - The
for-each-refoutput is the short refname for every branch, i.e., every ref inrefs/heads/. Thus, if your complete set of branch names are, for instance,monty,python,flying, andcircusand you're on branchflying, this listsmonty,python, andcircus. - Finally, we give all of this to
--not, after askinggit logto start atHEAD. Thelogcommand usesgit rev-listto start from wherever you ask it, and keep going backwards until something (in this case, the--notlist) makes it stop. And of course we add"$@"so that any other command-line arguments are included.
Since it's a one liner, it can be embedded in ~/.gitconfig, as an alias:
[alias]
ltf = !git log HEAD --not $(git for-each-ref \
--format='%(refname:short)' refs/heads | \
grep -v "^$(git symbolic-ref -q --short HEAD)$")
and now git ltf, git ltf --oneline, etc., all do the trick. (I don't know if I like the name ltf, it stands for "log to fork" but this is more of a "log to join". Maybe lbr for "log branch"?)
要查看哪些提交在一个分支上但不在另一个分支上的列表,请使用 git log:
git log oldbranch ^newbranch --no-merges
显示旧分支上所有不在新分支上的提交的提交日志。
此外,您可以列出要包含和排除的多个分支,例如
git log oldbranch1 oldbranch2 ^newbranch1 ^newbranch2 --no-merges