本文介绍了使用Git,显示所有提交* only *在一个特定的分支上,而不是*任何*其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个分支,我希望看到该分支上仅存在 的提交列表。在我们讨论如何查看哪些提交在一个分支上,而不是一个或多个指定的其他分支。

这略有不同。我希望看到哪些提交在一个分支上,但不在任何其他分支上。



用例处于分支策略中一些分支只应该合并到,而不是直接承诺。这将用于检查是否有任何提交已直接在仅合并分支上进行。



编辑:下面是设置一个虚拟git回购的步骤test:

  git init 
echo foo1 >> foo.txt
git add foo.txt
git commit -am初始有效提交
git checkout -b合并
echo bar >> bar.txt
git add bar.txt
git commit -am 直接在合并时提交错误
git checkout master
echo foo2 >> foo.txt
git commit -am在master上执行第二个有效提交
git checkout merge-只有
git merge master

只有提交信息bad直接在仅合并提交,它是直接在合并分支上创建的,应该显示出来。 解决方案

=https://serverfault.com/users/52693/redmumba> Redmumba :

  git log  - -no-merges origin / merge-only \ 
--not $(git for-each-re f --format =%(refname)refs / remotes / origin |
grep -Fv refs / remotes / origin / merge-only)

... where origin / merge-only 是您的远程合并分支名称。如果在一个仅限本地的git仓库中工作,用 refs / heads 替换 refs / remotes / origin ,并替换remote分支名称 origin / merge-only 与本地分支名称仅合并,即:

  git log --no-merges merge-only \ 
--not $(git for-each-ref --format =% (refname)refs / heads |
grep -Fv refs / heads / merge-only)


Given a branch, I'd like to see a list of commits that exist only on that branch. In this question we discuss ways to see which commits are on one branch but not one or more specified other branches.

This is slightly different. I'd like to see which commits are on one branch but not on any other branches.

The use case is in a branching strategy where some branches should only be merged to, and never committed directly on. This would be used to check if any commits have been made directly on a "merge-only" branch.

EDIT: Below are steps to set up a dummy git repo to test:

git init
echo foo1 >> foo.txt
git add foo.txt
git commit -am "initial valid commit"
git checkout -b merge-only
echo bar >> bar.txt
git add bar.txt
git commit -am "bad commit directly on merge-only"
git checkout master
echo foo2 >> foo.txt 
git commit -am "2nd valid commit on master"
git checkout merge-only 
git merge master

Only the commit with message "bad commit directly on merge-only", which was made directly on the merge-only branch, should show up.

解决方案

Courtesy of my dear friend Redmumba:

git log --no-merges origin/merge-only \
    --not $(git for-each-ref --format="%(refname)" refs/remotes/origin |
    grep -Fv refs/remotes/origin/merge-only)

...where origin/merge-only is your remote merge-only branch name. If working on a local-only git repo, substitute refs/remotes/origin with refs/heads, and substitute remote branch name origin/merge-only with local branch name merge-only, i.e.:

git log --no-merges merge-only \
    --not $(git for-each-ref --format="%(refname)" refs/heads |
    grep -Fv refs/heads/merge-only)

这篇关于使用Git,显示所有提交* only *在一个特定的分支上,而不是*任何*其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:45