简体   繁体   English

Git 日志以仅获取特定分支的提交

[英]Git log to get commits only for a specific branch

I want to list all commits that are only part of a specific branch.我想列出仅属于特定分支的所有提交。

With the following, it lists all the commits from the branch, but also from the parent (master)通过以下内容,它列出了来自分支的所有提交,也列出了来自父级(master)的所有提交

git log mybranch

The other option I found, was to exclude the commits reachable by master and gives me what I want, BUT I would like to avoid the need of knowing the other branches names.我发现的另一个选择是排除 master 可以访问的提交并给我我想要的,但我想避免知道其他分支名称的需要。

git log mybranch --not master

I was trying to use git for-each-ref , but it is also listing mybranch so actually it is excluding all:我试图使用git for-each-ref ,但它也列出了 mybranch 所以实际上它排除了所有:

git log mybranch --not $(git for-each-ref --format '^%(refname:short)' refs/heads/)

Update:更新:

I'm testing a new option that I found a while ago, and till now seems that this could be what I was looking for:我正在测试不久前发现的一个新选项,直到现在看来这可能就是我要找的东西:

git log --walk-reflogs mybranch

Update (2013-02-13T15:08):更新(2013-02-13T15:08):

The --walk-reflogs option is good, but I checked that there is an expiration for reflogs (default 90 days, gc.reflogExpire ). --walk-reflogs 选项很好,但我检查了 reflogs 是否过期(默认 90 天, gc.reflogExpire )。

I think I found the answer I was looking for:我想我找到了我要找的答案:

git log mybranch --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "refs/heads/mybranch")

I'm just removing the current branch from list of branches available and using that list to be excluded from the log.我只是从可用分支列表中删除当前分支,并使用该列表从日志中排除。 This way I only get the commits that are only reached by mybranch .这样我只能得到只有 mybranch 才能达到的提交

From what it sounds like you should be using cherry :从听起来你应该使用cherry来看:

git cherry -v develop mybranch

This would show all of the commits which are contained within mybranch , but NOT in develop .这将显示包含在mybranch 中的所有提交,但不包含在develop 中 If you leave off the last option ( mybranch ), it will compare the current branch instead.如果您不使用最后一个选项 ( mybranch ),它将改为比较当前分支。

As VonC pointed out, you are ALWAYS comparing your branch to another branch, so know your branches and then choose which one to compare to.正如 VonC 指出的那样,您总是将您的分支与另一个分支进行比较,因此请了解您的分支,然后选择要比较的分支。

BUT I would like to avoid the need of knowing the other branches names.但我想避免知道其他分支名称的需要。

I don't think this is possible: a branch in Git is always based on another one or at least on another commit, as explained in " git diff doesn't show enough ":我认为这是不可能的:Git 中的一个分支总是基于另一个或至少基于另一个提交,如“ git diff 显示不够”中所述:

在此处输入图片说明

You need a reference point for your log to show the right commits.您需要一个日志参考点来显示正确的提交。

As mentioned in " GIT - Where did I branch from? ":如“ GIT - 我从哪里分支? ”中所述:

branches are simply pointers to certain commits in a DAG分支只是指向 DAG 中某些提交的指针

So even if git log master..mybranch is one answer, it would still show too many commits, if mybranch is based on myotherbranch , itself based on master .因此,即使git log master..mybranch是一个答案,如果mybranch基于myotherbranch而本身基于master ,它仍然会显示太多提交。

In order to find that reference (the origin of your branch), you can only parse commits and see in which branch they are, as seen in:为了找到该引用(您的分支的来源),您只能解析提交并查看它们在哪个分支中,如下所示:

I finally found the way to do what the OP wanted.我终于找到了做 OP 想要做的事情的方法。 It's as simple as:这很简单:

git log --graph [branchname]

The command will display all commits that are reachable from the provided branch in the format of graph.该命令将以图形格式显示从提供的分支可访问的所有提交。 But, you can easily filter all commits on that branch by looking at the commits graph whose * is the first character in the commit line.但是,您可以通过查看其*是提交行中第一个字符的提交图轻松过滤该分支上的所有提交。

For example, let's look at the excerpt of git log --graph master on cakephp GitHub repo below:例如,让我们看看下面 cakephp GitHub repo 上git log --graph master的摘录:

D:\Web Folder\cakephp>git log --graph master
*   commit 8314c2ff833280bbc7102cb6d4fcf62240cd3ac4
|\  Merge: c3f45e8 0459a35
| | Author: José Lorenzo Rodríguez <lorenzo@users.noreply.github.com>
| | Date:   Tue Aug 30 08:01:59 2016 +0200
| |
| |     Merge pull request #9367 from cakephp/fewer-allocations
| |
| |     Do fewer allocations for simple default values.
| |
| * commit 0459a35689fec80bd8dca41e31d244a126d9e15e
| | Author: Mark Story <mark@mark-story.com>
| | Date:   Mon Aug 29 22:21:16 2016 -0400
| |
| |     The action should only be defaulted when there are no patterns
| |
| |     Only default the action name when there is no default & no pattern
| |     defined.
| |
| * commit 80c123b9dbd1c1b3301ec1270adc6c07824aeb5c
| | Author: Mark Story <mark@mark-story.com>
| | Date:   Sun Aug 28 22:35:20 2016 -0400
| |
| |     Do fewer allocations for simple default values.
| |
| |     Don't allocate arrays when we are only assigning a single array key
| |     value.
| |
* |   commit c3f45e811e4b49fe27624b57c3eb8f4721a4323b
|\ \  Merge: 10e5734 43178fd
| |/  Author: Mark Story <mark@mark-story.com>
|/|   Date:   Mon Aug 29 22:15:30 2016 -0400
| |
| |       Merge pull request #9322 from cakephp/add-email-assertions
| |
| |       Add email assertions trait
| |
| * commit 43178fd55d7ef9a42706279fa275bb783063cf34
| | Author: Jad Bitar <jadbitar@mac.com>
| | Date:   Mon Aug 29 17:43:29 2016 -0400
| |
| |     Fix `@since` in new files docblocks
| |

As you can see, only commits 8314c2ff833280bbc7102cb6d4fcf62240cd3ac4 and c3f45e811e4b49fe27624b57c3eb8f4721a4323b have the * being the first character in the commit lines.如您所见,只有提交8314c2ff833280bbc7102cb6d4fcf62240cd3ac4c3f45e811e4b49fe27624b57c3eb8f4721a4323b的第一个字符为* Those commits are from the master branch while the other four are from some other branches.这些提交来自 master 分支,而其他四个来自其他一些分支。

The following shell command should do what you want:以下 shell 命令应该执行您想要的操作:

git log --all --not $(git rev-list --no-walk --exclude=refs/heads/mybranch --all)

Caveats注意事项

If you have mybranch checked out, the above command won't work.如果您已mybranch ,则上述命令将不起作用。 That's because the commits on mybranch are also reachable by HEAD , so Git doesn't consider the commits to be unique to mybranch .这是因为mybranch上的提交也可以通过HEAD访问,所以 Git 不认为提交是mybranch To get it to work when mybranch is checked out, you must also add an exclude for HEAD :要在mybranch时使其正常工作,您还必须为HEAD添加一个排除项:

git log --all --not $(git rev-list --no-walk \
    --exclude=refs/heads/mybranch \
    --exclude=HEAD \
    --all)

However, you should not exclude HEAD unless the mybranch is checked out, otherwise you risk showing commits that are not exclusive to mybranch .但是,你应该排除HEAD ,除非mybranch被检查出来,否则你可能会显示出并不互斥提交mybranch

Similarly, if you have a remote branch named origin/mybranch that corresponds to the local mybranch branch, you'll have to exclude it:同样,如果您有一个名为origin/mybranch的远程分支与本地mybranch分支相对应,则必须将其排除:

git log --all --not $(git rev-list --no-walk \
    --exclude=refs/heads/mybranch \
    --exclude=refs/remotes/origin/mybranch \
    --all)

And if the remote branch is the default branch for the remote repository (usually only true for origin/master ), you'll have to exclude origin/HEAD as well:如果远程分支是远程存储库的默认分支(通常仅适用于origin/master ),您还必须排除origin/HEAD

git log --all --not $(git rev-list --no-walk \
    --exclude=refs/heads/mybranch \
    --exclude=refs/remotes/origin/mybranch \
    --exclude=refs/remotes/origin/HEAD \
    --all)

If you have the branch checked out, and there's a remote branch, and the remote branch is the default for the remote repository, then you end up excluding a lot:如果您已签出分支,并且有一个远程分支,并且远程分支是远程存储库的默认分支,那么您最终会排除很多:

git log --all --not $(git rev-list --no-walk \
    --exclude=refs/heads/mybranch \
    --exclude=HEAD
    --exclude=refs/remotes/origin/mybranch \
    --exclude=refs/remotes/origin/HEAD \
    --all)

Explanation解释

The git rev-list command is a low-level (plumbing) command that walks the given revisions and dumps the SHA1 identifiers encountered. git rev-list命令是一个低级(管道)命令,它遍历给定的修订并转储遇到的 SHA1 标识符。 Think of it as equivalent to git log except it only shows the SHA1—no log message, no author name, no timestamp, none of that "fancy" stuff.把它想象成等价于git log只是它只显示 SHA1——没有日志消息,没有作者姓名,没有时间戳,没有那些“花哨”的东西。

The --no-walk option, as the name implies, prevents git rev-list from walking the ancestry chain. --no-walk选项,顾名思义,可以防止git rev-list遍历祖先链。 So if you type git rev-list --no-walk mybranch it will only print one SHA1 identifier: the identifier of the tip commit of the mybranch branch.所以如果你输入git rev-list --no-walk mybranch它只会打印一个 SHA1 标识符: mybranch分支的提示提交的mybranch

The --exclude=refs/heads/mybranch --all arguments tell git rev-list to start from each reference except for refs/heads/mybranch . --exclude=refs/heads/mybranch --all参数告诉git rev-list从每个引用开始,除了refs/heads/mybranch

So, when you run git rev-list --no-walk --exclude=refs/heads/mybranch --all , Git prints the SHA1 identifier of the tip commit of each ref except for refs/heads/mybranch .因此,当您运行git rev-list --no-walk --exclude=refs/heads/mybranch --all ,Git 会打印每个 ref 的提示提交的 SHA1 标识符,除了refs/heads/mybranch These commits and their ancestors are the commits you are not interested in—these are the commits you do not want to see.这些提交和他们的祖先是您没有,这些都是你希望看到的提交感兴趣的提交。

The other commits are the ones you want to see, so we collect the output of git rev-list --no-walk --exclude=refs/heads/mybranch --all and tell Git to show everything but those commits and their ancestors.其他提交是你想看到的,所以我们收集git rev-list --no-walk --exclude=refs/heads/mybranch --all并告诉 Git 显示除那些提交及其祖先之外的所有内容.

The --no-walk argument is necessary for large repositories (and is an optimization for small repositories): Without it, Git would have to print, and the shell would have to collect (and store in memory) many more commit identifiers than necessary. --no-walk参数对于大型存储库是必需的(并且是对小型存储库的优化):没有它,Git 将不得不打印,并且 shell 将不得不收集(并存储在内存中)比必要更多的提交标识符. With a large repository, the number of collected commits could easily exceed the shell's command-line argument limit.对于大型存储库,收集的提交数量很容易超过 shell 的命令行参数限制。

Git bug?吉特错误?

I would have expected the following to work:我本来希望以下内容起作用:

git log --all --not --exclude=refs/heads/mybranch --all

but it does not.但事实并非如此。 I'm guessing this is a bug in Git, but maybe it's intentional.我猜这是 Git 中的一个错误,但也许是故意的。

Fast answer:快速回答:

git log $(git merge-base master b2)..HEAD

Let's say:让我们说:

  1. That you have a master branch你有一个分支

  2. Do a few commits做一些提交

  3. You created a branch named b2您创建了一个名为b2的分支

  4. Do git log -n1 ;git log -n1 ; the commit Id is the merge base between b2 and master提交 ID 是 b2 和 master 之间的合并基础

  5. Do a few commits in b2b2 中做一些提交

  6. git log will show your log history of b2 and master git log会显示你的 b2 和 master 的日志历史

  7. Use commit range, if you aren't familiar with the concept, I invite you to google it or stack overflow-it,使用commit range,如果你不熟悉这个概念,我请你google一下或者stackoverflow-it,

    For your actual context, you can do for example对于您的实际上下文,您可以执行例如

    git log commitID_FOO..comitID_BAR

    The ".." is the range operator for the log command. “..”是日志命令的范围运算符。

    That mean, in a simple form, give me all logs more recent than commitID_FOO...这意味着,以简单的形式,给我所有比 commitID_FOO 更新的日志......

  8. Look at point #4, the merge base看点#4,合并基础

    So: git log COMMITID_mergeBASE..HEAD will show you the difference所以: git log COMMITID_mergeBASE..HEAD会告诉你区别

  9. Git can retrieve the merge base for you like this Git可以像这样为你检索合并基础

    git merge-base b2 master
  10. Finally you can do:最后你可以这样做:

     git log $(git merge-base master b2)..HEAD

I'm using the following commands:我正在使用以下命令:

git shortlog --no-merges --graph --abbrev-commit master..<mybranch>

or要么

git log --no-merges --graph --oneline --decorate master..<mybranch>

You could try something like this:你可以尝试这样的事情:

#!/bin/bash

all_but()
{
    target="$(git rev-parse $1)"
    echo "$target --not"
    git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
    while read entry
    do
        eval "$entry"

        test "$ref" != "$target" && echo "$ref"
    done
}

git log $(all_but $1)

Or, borrowing from the recipe in the Git User's Manual :或者,借用Git 用户手册中配方

#!/bin/bash
git log $1 --not $( git show-ref --heads | cut -d' ' -f2 | grep -v "^$1" )

This will output the commits on the current branch.这将输出当前分支上的提交。 If any argument is passed, it just outputs the hashes.如果传递了任何参数,它只会输出哈希值。

git_show_all_commits_only_on_this_branch git_show_all_commits_only_on_this_branch

#!/bin/bash
function show_help()
{
  ME=$(basename $0)
  IT=$(cat <<EOF
  
  usage: $ME {NEWER_BRANCH} {OLDER_BRANCH} {VERBOSE}
  
  Compares 2 different branches, and lists the commits found only 
  in the first branch (newest branch). 

  e.g. 
  
  $ME         -> default. compares current branch to master
  $ME B1      -> compares branch B1 to master
  $ME B1 B2   -> compares branch B1 to B2
  $ME B1 B2 V -> compares branch B1 to B2, and displays commit messages
  
  )
  echo "$IT"
  exit
}

if [ "$1" == "help" ]
then
  show_help
fi

# Show commit msgs if any arg passed for arg 3
if [ "$3" ]
then
  OPT="-v"
fi

# get branch names
OLDER_BRANCH=${2:-"master"}
if [ -z "$1" ]
then
  NEWER_BRANCH=$(git rev-parse --abbrev-ref HEAD)
else
  NEWER_BRANCH=$1
fi

if [ "$NEWER_BRANCH" == "$OLDER_BRANCH" ]
then
  echo "  Please supply 2 different branches to compare!"
  show_help
fi

OUT=$(\git cherry $OPT $OLDER_BRANCH $NEWER_BRANCH)

if [ -z "$OUT" ]
then
  echo "No differences found. The branches $NEWER_BRANCH and $OLDER_BRANCH are in sync."
  exit;
fi

if [ "$OPT" == "-v" ]
then
  echo "$OUT"
else
  echo "$OUT" | awk '{print $2}'
fi
git rev-list --exclude=master --branches --no-walk

will list the tips of every branch that isn't master .将列出不是master的每个分支的提示。

git rev-list master --not $(git rev-list --exclude=master --branches --no-walk)

will list every commit in master 's history that's not in any other branch's history.将列出master历史中所有不在任何其他分支历史中的提交。

Sequencing is important for the options that set up the filter pipeline for commit selection, so --branches has to follow any exclusion patterns it's supposed to apply, and --no-walk has to follow the filters supplying commits rev-list isn't supposed to walk.排序对于为提交选择设置过滤器管道的选项很重要,因此--branches必须遵循它应该应用的任何排除模式,并且--no-walk必须遵循提供提交的过滤器 rev-list 不是应该走路。

I found this approach relatively easy.我发现这种方法相对容易。

Checkout to the branch and than结帐到分行,然后

  1. Run跑步

    git rev-list --simplify-by-decoration -2 HEAD

This will provide just two SHAs:这将仅提供两个 SHA:

1) last commit of the branch [C1] 1) 分支的最后一次提交 [C1]

2) and commit parent to the first commit of the branch [C2] 2) 并将父级提交到分支的第一次提交 [C2]

  1. Now run现在运行

    git log --decorate --pretty=oneline --reverse --name-status <C2>..<C1>

Here C1 and C2 are two strings you will get when you run first command.这里 C1 和 C2 是你运行第一个命令时会得到的两个字符串。 Put these values without <> in second command.将这些值不带 <> 放在第二个命令中。

This will give list of history of file changing within the branch.这将给出分支内文件更改的历史列表。

Here I present an alias based on Richard Hansen's answer (and Ben C's suggestion), but that I adapted to exclude tags.在这里,我根据 Richard Hansen 的回答(和 Ben C 的建议)提出了一个别名,但我已经适应了排除标签。 The alias should be fairly robust.别名应该相当健壮。

# For Git 1.22+
git config --global alias.only '!b=${1:-$(git branch --show-current)}; git log --oneline --graph "heads/$b" --not --exclude="$b" --branches --remotes #'
# For older Git:
git config --global alias.only '!b=${1:-$(git symbolic-ref -q --short HEAD)}; b=${b##heads/}; git log --oneline --graph "heads/$b" --not --exclude="$b" --branches --remotes #'

Example of use:使用示例:

git only mybranch  # Show commits that are in mybranch ONLY
git only           # Show commits that are ONLY in current branch

Note that ONLY means commits that would be LOST (after garbage collection) if the given branch was deleted (excluding the effect of tags).请注意,如果给定分支被删除(不包括标签的影响),则ONLY意味着提交将丢失(垃圾回收后)。 The alias should work even if there is unfortunately a tag named mybranch (thanks to prefix heads/ ).即使不幸有一个名为mybranch的标签(感谢前缀heads/ ),别名也应该可以工作。 Note also that no commits are shown if they are part of any remote branch (including upstream if any), in compliance with the definition of ONLY .另请注意,如果提交是任何远程分支(包括上游,如果有的话)的一部分,则不会显示任何提交,符合ONLY的定义。

The alias shows the one-line history as a graph of the selected commits.别名将单行历史显示为所选提交的图表。

  a --- b --- c --- master
   \           \
    \           d
     \           \
      e --- f --- g --- mybranch (HEAD)
       \
        h --- origin/other

With example above, git only would show:在上面的例子中, git only显示:

  * (mybranch,HEAD)
  * g
  |\
  | * d
  * f 

In order to include tags (but still excluding HEAD ), the alias becomes (adapt as above for older Git):为了包含标签(但仍然不包括HEAD ),别名变为(如上适应旧版 Git):

git config --global alias.only '!b=${1:-$(git branch --show-current)};  git log --oneline --graph --all --not --exclude="refs/heads/$b" --exclude=HEAD --all #'

Or the variant that includes all the tags including HEAD (and removing current branch as default since it won't output anything):或者包含所有标签的变体,包括 HEAD(并默认删除当前分支,因为它不会输出任何内容):

git config --global alias.only '!git log --oneline --graph --all --not --exclude=\"refs/heads/$1\" --all #'

This last version is the only one that really satisfies the criteria commits-that-are-lost-if-given-branch-is-deleted, since a branch cannot be deleted if it is checked out, and no commit pointed by HEAD or any other tag will be lost.最后一个版本是唯一真正满足 commits-that-are-lost-if-given-branch-is-deleted 标准的版本,因为如果分支被检出,则无法删除,并且 HEAD 或任何其他标签将丢失。 However the first two variants are more useful.然而,前两个变体更有用。

Finally, the alias does not work with remote branches (eg. git only origin/master ).最后,别名不适用于远程分支(例如git only origin/master )。 The alias must be modified, for instance:必须修改别名,例如:

git config --global alias.remote-only '!git log --oneline --graph "$1" --not --exclude="$1" --remotes --branches #'

In my situation, we are using Git Flow and GitHub.在我的情况下,我们使用 Git Flow 和 GitHub。 All you need to do this is: Compare your feature branch with your develop branch on GitHub.您需要做的就是:将您的功能分支与 GitHub 上的开发分支进行比较。

It will show the commits only made to your feature branch.它将显示仅对您的功能分支进行的提交。

For example:例如:

https://github.com/your_repo/compare/develop...feature_branch_name https://github.com/your_repo/compare/develop...feature_branch_name

I needed to export log in one line for a specific branch.我需要为特定分支导出一行日志。

So I probably came out with a simpler solution.所以我可能想出了一个更简单的解决方案。
When doing git log --pretty=oneline --graph we can see that all commit not done in the current branch are lines starting with |在执行git log --pretty=oneline --graph我们可以看到当前分支中未完成的所有提交都是以|开头的行|

So a simple grep -v do the job:所以一个简单的grep -v就可以完成这项工作:
git log --pretty=oneline --graph | grep -v "^|"

Of course you can change the pretty parameter if you need other info, as soon as you keep it in one line.当然,如果您需要其他信息,您可以更改漂亮参数,只要将其保留在一行中即可。

You probably want to remove merge commit too.您可能也想删除合并提交。
As the message start with "Merge branch", pipe another grep -v and you're done.当消息以“合并分支”开头时,再输入一个grep -v就完成了。

In my specific ase, the final command was:在我的特定情况下,最终命令是:
git log --pretty="%ad : %an, %s" --graph | grep -v "^|" | grep -v "Merge branch"

From the above comments what I see that - you want only those commits belong to that branch only not to its parent.从上面的评论中我看到 - 你只希望那些提交属于那个分支而不是它的父分支。 But technically if you think - when you create a branch from an another branch those commits also copy to the child branch.但从技术上讲,如果您认为 - 当您从另一个分支创建分支时,这些提交也会复制到子分支。 But for your question the following commands will work.但是对于您的问题,以下命令将起作用。

git log childBranch...parentBranch

if the parent branch is a remote branch you can use the following command.如果父分支是远程分支,您可以使用以下命令。

git log yourBranch --not --remotes=origin

Option 1 (seems faster but you may get the error bash: /mingw64/bin/git: Argument list too long in Git Bash (it worked in Linux though) depending on how many branches your project has)选项 1 (看起来更快,但您可能会收到错误bash: /mingw64/bin/git: Argument list too long in Git Bash(尽管它在 Linux 中有效),具体取决于您的项目有多少个分支)

git log <your_branch> --not $(git branch -a | grep -v <your_branch> | grep -ve '->' | sed "s/\\s//g")

Option 2选项 2

git rev-list <your_branch> | git name-rev --stdin | sed -E 's/~[0-9]+//g; s/\\^[0-9]+//g' | grep " <your_branch>" | awk -F " " '{print $1}'

I manage to do it by using git log <branch> There is also an option to --not <branch-name> original documentation : git-log我设法通过使用git log <branch>来做到这一点 还有一个选项--not <branch-name>原始文档: git-log

example with format:格式示例:

git log branch-name  --date-order --format='%ai %an <%ae> %h %f'--format='%ai , %an ,<%ae> ,%h ,%f' >> c:\log.csv

This still was discussed in 2021 and the question was asked 8 years ago.这仍然在 2021 年讨论过,这个问题是 8 年前提出的。 I am puzzled why nobody is suggesting git --first-parent.我很困惑为什么没有人建议使用 git --first-parent。 Isn't that the solution nowadays?这不是现在的解决方案吗? I currently have the same problem and this looks quite fine to me.我目前有同样的问题,这对我来说看起来很好。 I combined those options:我结合了这些选项:

git --first-parent --cherry  first-commit-on-branch..

I even merged further commits from master into my feature branch, but those commits are filtered out because of cherry which is a combination of --cherry-pick, --right-only and --no-merges.我什至将来自 master 的进一步提交合并到我的功能分支中,但是由于cherry 是--cherry-pick、--right-only 和--no-merges 的组合,这些提交被过滤掉了。 You manually need to find out the first commit on your branch or a commit from then on you want to find all following commits.您需要手动找出分支上的第一个提交或从那时起您想要查找所有后续提交的提交。

I made an alias to be able to simply type "git logbranch" and have all of the commits specific to your current branch.我创建了一个别名,以便能够简单地输入“git logbranch”并拥有特定于您当前分支的所有提交。 Here is the alias:这是别名:

[alias]
    logbranch = "!cd -- \"${GIT_PREFIX:-.}\" && CURRENT_BRANCH=$(git branch --show-current) && git log $CURRENT_BRANCH --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v refs/heads/$CURRENT_BRANCH) #"

NB: Put that under the [alias] tag in the.gitconfig file, located in your home directory.注意:将其放在位于主目录中的 .gitconfig 文件中的 [alias] 标记下。

So, I basically used what has been originally posted in the question post and used the CURRENT_BRANCH variable to make it quicker.所以,我基本上使用了问题帖子中最初发布的内容,并使用了 CURRENT_BRANCH 变量来使其更快。 Hope this will save you some time希望这会为您节省一些时间

This works:这有效:

for a in $(git rev-list anybranch..mybranch); do echo -n "$a "; git branch --contains $a | xargs; done

You could use a draconian git rev-list --all but if you only care about commits not somewhere else, choosing any branch you think you came from will at least limit the range and you can see at a glance which commit(s) only belong to that branch.您可以使用严苛的git rev-list --all但如果您只关心提交而不关心其他地方,选择您认为您来自的任何分支至少会限制范围,您可以一目了然地看到哪些提交属于那个分支。

anybranch..mybranch is the same as mybranch --not anybranch or set mybranch - set anybranch from set theory while ... is the disjoint set, A not in B and B not in A anybranch..mybranch与 mybranch 相同mybranch --not anybranchset mybranch - set anybranch from set theory while ...是不相交的集合,A 不在 B 中,B 不在 A 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM