确定特定提交何时合并到git分支
项目描述
git when-merged
git when-merged
帮助您了解提交何时以及为什么被合并到分支中。
如果您使用标准的Git工作流程,那么您将为每个正在工作的功能创建一个功能分支。当功能完成时,您将其合并到您的master
分支。您甚至可能有在合并到功能分支之前先合并到功能分支的子功能分支。
在这样的工作流程中,master
的第一父历史主要是由功能分支合并到主线的历史记录。可以使用git when-merged
来询问,“提交C何时(以及为什么)被合并到当前分支?”使用它的最简单方法是
$ git when-merged 87c248f
refs/heads/master 50f577451448a407ee8e78ed62aa09d209c91652
此命令沿着当前分支的第一父历史查找首次将提交87c248f
引入分支历史记录的合并提交。在这个案例中,有罪的合并提交是50f5774
。添加-l
选项以查看该合并的日志,这可能会解释正在合并的功能以及由谁合并
$ git when-merged -l 87c248f
refs/heads/master 50f577451448a407ee8e78ed62aa09d209c91652
commit 50f577451448a407ee8e78ed62aa09d209c91652 (github/master, master)
Merge: f79a45d 87c248f
Author: Michael Haggerty <mhagger@alum.mit.edu>
Date: Mon Jul 11 07:55:19 2016 +0200
Merge pull request #9 from mhagger/recursive-option
Add a `--recursive`/`-r` option
还有更多选项;请见下文。
安装
注意:如果您使用2.6 <= Python <= 3.6,您必须使用选项3或4。
选项1:作为独立命令行工具安装。
pipx是一个工具,可帮助您安装和运行用Python编写的最终用户应用程序。
-
python3 -m pip install --user pipx
- 提示:Homebrew 以及一些 Linux 发行版的新版本(例如 Debian 10、Ubuntu 19.04 等)都为
pipx
提供了本地安装包。
python3 -m pipx ensurepath
- 注意:您可能需要重启终端,以使
$PATH
更新生效。
- 提示:Homebrew 以及一些 Linux 发行版的新版本(例如 Debian 10、Ubuntu 19.04 等)都为
-
使用
pipx
安装来自 PyPI 的git-when-merged
pipx install git-when-merged
-
测试安装
git-when-merged --help
-
在任何时候都可以使用
pipx
进行卸载pipx uninstall git-when-merged
有关更多信息,请参阅 Python 的 安装独立命令行工具 指南。
选项 2:创建临时安装。
Python "虚拟环境" 允许将 Python 包安装在特定应用程序的独立位置,而不是全局安装。
-
使用内置的
venv
模块创建虚拟环境python3 -m venv ./venv-gwm
-
将
git-when-merged
安装到虚拟环境中venv-gwm/bin/pip install git-when-merged
-
测试安装
venv-gwm/bin/git-when-merged --help
-
提示:一些用户发现激活虚拟环境(将虚拟环境的
bin/
添加到$PATH
)更为方便。source venv-gwm/bin/activate git-when-merged --help deactivate
-
-
要卸载,可以随时删除虚拟环境
rm --recursive venv-gwm/
有关更多信息,请参阅 Python 的 安装包 教程。
选项 3:克隆并添加到 $PATH
。
$PATH
。-
在系统上的某个位置克隆仓库。
-
确保
<somewhere>/bin/git-when-merged
可执行。 -
将
<somewhere>/bin
的内容添加到您的$PATH
。
这样就完成了!
选项 4(MacOS 用户):使用 Homebrew 安装。
$ brew update
$ brew install git-when-merged
用法
git when-merged [OPTIONS] COMMIT [BRANCH...]
查找将 COMMIT
带入指定 BRANCH
(es) 的合并提交。具体来说,查找每个 BRANCH
首先父历史中包含 COMMIT
作为祖先的最旧的提交。
positional arguments:
commit The commit whose destiny you would like to determine.
branch The destination branch(es) into which <commit> might
have been merged. (Actually, BRANCH can be an
arbitrary commit, specified in any way that is
understood by git-rev-parse(1).) If neither <branch>
nor --pattern/-p nor --default/-s is specified, then
HEAD is used.
optional arguments:
-h, --help show this help message and exit
--pattern PATTERN, -p PATTERN
Show when COMMIT was merged to the references matching
the specified regexp. If the regexp has parentheses
for grouping, then display in the output the part of
the reference name matching the first group.
--name NAME, -n NAME Show when COMMIT was merged to the references matching
the configured pattern(s) with the given name (see
whenmerged.<name>.pattern below under CONFIGURATION).
--default, -s Shorthand for "--name=default".
--recursive, -r Follow merges back recursively.
--show-commit, -c Display only the SHA-1 of the merge commit. Exit with
a nonzero exit code if the commit was not merged via a
merge commit.
--show-branch, -b Display the range of commits that were merged at the
same time as the specified commit. Exit with a nonzero
exit code if the commit was not merged via a merge
commit. This option also affects the behavior of --log
and --visualize.
--abbrev N Abbreviate commit SHA-1s to the specified number of
characters (or more if needed to avoid ambiguity). See
also whenmerged.abbrev below under CONFIGURATION.
--no-abbrev Do not abbreviate commit SHA-1s.
--describe Describe the merge commit in terms of the most recent
tag reachable from the commit (see git-describe(1))
--describe-contains Describe the merge commit in terms of a nearby tag
that contains it (see git-describe(1))
--log, -l Show the log for the merge commit. When used with
"--show-branch/-b", show the log for all of the
commits that were merged at the same time as the
specified commit.
--diff, -d Show the diff for the merge commit.
--visualize, -v Visualize the merge commit using gitk. When used with
"--show-branch/-b", only show the branch(es) that were
merged at the same time as the specified commit.
Examples:
git when-merged 0a1b # Find the merge commit that brought
# commit 0a1b into the current branch
git when-merged 0a1b v1.10 v1.11 # Find merge into given tags/branches
git when-merged 0a1b -p feature-[0-9]+ # Specify tags/branches by regex
git when-merged 0a1b -n releases # Use whenmerged.releases.pattern
git when-merged 0a1b -s # Use whenmerged.default.pattern
git when-merged -r 0a1b # If the commit was merged indirectly,
# show each intermediate merge.
git when-merged -l 0a1b # Show the log for the merge commit
git when-merged -lb 0a1b # Show log for the whole merged branch
git when-merged -v 0a1b # Visualize the merge commit in gitk
git when-merged -vb 0a1b # Visualize the whole merged branch
git when-merged -d 0a1b # Show the diff for the merge commit
git when-merged -c 0a1b # Print only the merge's SHA-1
Configuration:
whenmerged.<name>.pattern
Regular expressions that match reference names for the pattern
called <name>. A regexp is sought in the full reference name,
in the form "refs/heads/master". This option can be multivalued, in
which case references matching any of the patterns are considered.
Typically the pattern will be chosen to match master and/or significant
release branches or tags, or perhaps their remote-tracking equivalents.
For example,
git config whenmerged.default.pattern '^refs/heads/master$'
git config --add whenmerged.default.pattern '^refs/heads/maint$'
or
git config whenmerged.releases.pattern '^refs/tags/release-'
whenmerged.abbrev
If this value is set to a positive integer, then Git SHA-1s are
abbreviated to this number of characters (or longer if needed to
avoid ambiguity). This value can be overridden using --abbrev=N
or --no-abbrev.
git when-merged
最初基于这里的建议。
项目详情
下载文件
下载您平台上的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。