merge-base
NAME名
git-merge-base - Find as good common ancestors as possible for a mergegit-merge-base - マージのためにできるだけ良い共通の祖先を見つける
SYNOPSIS概要
git merge-base [-a|--all] <commit> <commit>… git merge-base [-a|--all] --octopus <commit>… git merge-base --is-ancestor <commit> <commit> git merge-base --independent <commit>… git merge-base --fork-point <ref> [<commit>]
DESCRIPTION説明
git merge-base finds best common ancestor(s) between two commits to use in a three-way merge. One common ancestor is better than another common ancestor if the latter is an ancestor of the former. A common ancestor that does not have any better common ancestor is a best common ancestor, i.e. a merge base. Note that there can be more than one merge base for a pair of commits.git merge-baseは、3者間マージで使用する2つのコミット間で最も一般的な先祖を見つけます。後者が前者の祖先である場合、ある共通の祖先は別の共通の祖先よりも優れています。より良い共通の祖先を持たない共通の祖先は、最良の共通の祖先、すなわちマージベースです。1対のコミットに対して複数のマージベースが存在する可能性があることに注意してください。
OPERATION MODES操作モード
As the most common special case, specifying only two commits on the command line means computing the merge base between the given two commits.最も一般的な特別な場合として、コマンドラインで2つのコミットだけを指定することは、与えられた2つのコミットの間でマージベースを計算することを意味します。
More generally, among the two commits to compute the merge base from, one is specified by the first commit argument on the command line; the other commit is a (possibly hypothetical) commit that is a merge across all the remaining commits on the command line.より一般的には、マージベースを計算するための2つのコミットのうち、1つはコマンドラインの最初のコミット引数によって指定されます。もう1つのコミットは(おそらく仮想の)コミットで、コマンドラインの残りのすべてのコミットをマージしたものです。
As a consequence, the merge base is not necessarily contained in each of the
commit arguments if more than two commits are specified. This is different
from git-show-branch[1] when used with the --merge-base
option.結果として、3 つ以上のコミットが指定されている場合、マージベースは必ずしも各コミット引数に含まれるわけではありません。このオプションと一緒に使用すると、git-show-branch [1]とは異なり--merge-base
ます。
- --octopus - たこ
-
Compute the best common ancestors of all supplied commits, in preparation for an n-way merge. This mimics the behavior of git show-branch --merge-base.n-wayマージに備えて、提供されたすべてのコミットの最も一般的な祖先を計算します。これはgit show-branch --merge-baseの動作を模倣しています。
- --independent - 独立
-
Instead of printing merge bases, print a minimal subset of the supplied commits with the same ancestors. In other words, among the commits given, list those which cannot be reached from any other. This mimics the behavior of git show-branch --independent.マージベースを印刷する代わりに、提供されたコミットの最小限のサブセットを同じ先祖で印刷します。言い換えれば、与えられたコミットの中で、他からは到達できないものをリストします。これはgit show-branch --independentの動作を模倣しています。
- --is-ancestor
-
Check if the first <commit> is an ancestor of the second <commit>, and exit with status 0 if true, or with status 1 if not. Errors are signaled by a non-zero status that is not 1.最初の<commit>が2番目の<commit>の先祖であるかどうかを確認し、trueの場合はステータス0で終了し、そうでない場合はステータス1で終了します。エラーは、1ではないゼロ以外のステータスによって通知されます。
- --fork-point - フォークポイント
-
Find the point at which a branch (or any history that leads to <commit>) forked from another branch (or any reference) <ref>. This does not just look for the common ancestor of the two commits, but also takes into account the reflog of <ref> to see if the history leading to <commit> forked from an earlier incarnation of the branch <ref> (see discussion on this mode below).ブランチ(または<commit>につながる履歴)が別のブランチ(または任意の参照)<ref>から分岐したポイントを見つけます。これは2つのコミットの共通の先祖を探すだけでなく、<commit>につながる履歴が分岐<ref>の初期の実体化から分岐したかどうかを確認するために<ref>のreflogも考慮に入れます。このモードは以下にあります。
OPTIONSオプション
- -a
- --all - すべて
-
Output all merge bases for the commits, instead of just one.コミットのマージベースを1つだけではなくすべて出力します。
DISCUSSION討論
Given two commits A and B, git merge-base A B
will output a commit
which is reachable from both A and B through the parent relationship.与えられた2つのコミットAとBは、git merge-base A B
出力は両方から到達可能であるコミットしますAとBの親関係を通じて。
For example, with this topology:たとえば、次のトポロジでは、
o---o---o---B / ---o---1---o---o---o---A
the merge base between A and B is 1.AとBの間のマージベースは1です。
Given three commits A, B and C, git merge-base A B C
will compute the
merge base between A and a hypothetical commit M, which is a merge
between B and C. For example, with this topology:3つのコミット所与のA、BとC、git merge-base A B C
の間のマージベース計算するA及びコミット仮説Mとの間のマージであり、BおよびCを。たとえば、次のトポロジでは、
o---o---o---o---C / / o---o---o---B / / ---2---1---o---o---o---A
the result of git merge-base A B C
is 1. This is because the
equivalent topology with a merge commit M between B and C is:の結果git merge-base A B C
は1です。マージと同等のトポロジーがコミットするためであるMの間でB及びCです。
o---o---o---o---o / \ / o---o---o---o---M / / ---2---1---o---o---o---A
and the result of git merge-base A M
is 1. Commit 2 is also a
common ancestor between A and M, but 1 is a better common ancestor,
because 2 is an ancestor of 1. Hence, 2 is not a merge base.そしての結果git merge-base A M
は1です。コミット2もAとMの間の共通の先祖ですが、2は1の先祖であるため、1がより一般的な先祖です。したがって、2はマージベースではありません。
The result of git merge-base --octopus A B C
is 2, because 2 is
the best common ancestor of all commits.2がすべてのコミットの最も一般的な祖先であるため、の結果git merge-base --octopus A B C
は2です。
When the history involves criss-cross merges, there can be more than one best common ancestor for two commits. For example, with this topology:歴史が十字交差合併を含むとき、2つのコミットのために1つ以上の最も一般的な祖先がある可能性があります。たとえば、次のトポロジでは、
---1---o---A \ / X / \ ---2---o---o---B
both 1 and 2 are merge-bases of A and B. Neither one is better than
the other (both are best merge bases). When the --all
option is not given,
it is unspecified which best one is output.両方の1および2は、 AとBの-塩基をマージしないどちらもが、(両方が他よりも優れている最良のマージ塩基)。--all
オプションが与えられていない場合、どの最良のものが出力されるかは指定されていません。
A common idiom to check "fast-forward-ness" between two commits A and B is (or at least used to be) to compute the merge base between A and B, and check if it is the same as A, in which case, A is an ancestor of B. You will see this idiom used often in older scripts.2つのコミットAとBの間の "早送り"をチェックするための一般的な慣用句は、AとBの間のマージベースを計算し、それがAと同じかどうかをチェックすることです(その場合)。 AはBの先祖です。この慣用句は古いスクリプトでよく使われます。
A=$(git rev-parse --verify A) if test "$A" = "$(git merge-base A B)" then ... A is an ancestor of B ... fi
In modern git, you can say this in a more direct way:現代のgitでは、これをもっと直接的な方法で言うことができます。
if git merge-base --is-ancestor A B then ... A is an ancestor of B ... fi
instead.代わりに。
Discussion on fork-point modeフォークポイントモードに関する議論
After working on the topic
branch created with git checkout -b
topic origin/master
, the history of remote-tracking branch
origin/master
may have been rewound and rebuilt, leading to a
history of this shape:でtopic
作成したブランチgit checkout -b topic origin/master
を操作した後、リモートトラッキングブランチの履歴はorigin/master
巻き戻されて再構築され、次のような形の履歴になります。
o---B2 / ---o---o---B1--o---o---o---B (origin/master) \ B0 \ D0---D1---D (topic)
where origin/master
used to point at commits B0, B1, B2 and now it
points at B, and your topic
branch was started on top of it back
when origin/master
was at B0, and you built three commits, D0, D1,
and D, on top of it. Imagine that you now want to rebase the work
you did on the topic on top of the updated origin/master.これまでorigin/master
はB0、B1、B2のコミットを指していましたが、現在はBを指してtopic
いてorigin/master
、B0 にあったときに分岐がその上で開始され、その上にD0、D1、およびDという3つのコミットが作成されました。 。更新された起源/マスターの上にあるトピックで行った作業をリベースしたいとします。
In such a case, git merge-base origin/master topic
would return the
parent of B0 in the above picture, but B0^..D is not the range of
commits you would want to replay on top of B (it includes B0, which
is not what you wrote; it is a commit the other side discarded when
it moved its tip from B0 to B1).このような場合、git merge-base origin/master topic
上の図ではB0の親を返しますが、B0 ^ .. DはBの上で再生したいコミットの範囲ではありません(B0が含まれています。反対側がB0からB1にチップを移動したときに破棄されたコミットです。
git merge-base --fork-point origin/master topic
is designed to
help in such a case. It takes not only B but also B0, B1, and B2
(i.e. old tips of the remote-tracking branches your repository’s
reflog knows about) into account to see on which commit your topic
branch was built and finds B0, allowing you to replay only the
commits on your topic, excluding the commits the other side later
discarded.git merge-base --fork-point origin/master topic
このような場合に役立つように設計されています。BだけでなくB0、B1、およびB2(つまり、リポジトリのreflogが知っているリモートトラッキングブランチの古いヒント)を考慮して、トピックブランチがどのコミットで構築され、B0が見つかったかを確認します。後で破棄された相手側のコミットを除く、あなたのトピックに関するコミット。
Henceそれゆえ
$ fork_point=$(git merge-base --fork-point origin/master topic)
will find B0, andB0が見つかります
$ git rebase --onto origin/master $fork_point topic
will replay D0, D1 and D on top of B to create a new history of this shape:この形の新しい履歴を作成するために、Bの上にD0、D1、およびDを再生します。
o---B2 / ---o---o---B1--o---o---o---B (origin/master) \ \ B0 D0'--D1'--D' (topic - updated) \ D0---D1---D (topic - old)
A caveat is that older reflog entries in your repository may be
expired by git gc
. If B0 no longer appears in the reflog of the
remote-tracking branch origin/master
, the --fork-point
mode
obviously cannot find it and fails, avoiding to give a random and
useless result (such as the parent of B0, like the same command
without the --fork-point
option gives).注意点は、リポジトリ内の古いreflogエントリが期限切れになる可能性があることgit gc
です。リモートトラッキングブランチのreflogにB0が表示されなくなった場合origin/master
、--fork-point
モードは明らかにそれを見つけることができず失敗し、ランダムで無駄な結果を与えることを避けます(--fork-point
オプションなしの同じコマンドのようにB0の親など)。
Also, the remote-tracking branch you use the --fork-point
mode
with must be the one your topic forked from its tip. If you forked
from an older commit than the tip, this mode would not find the fork
point (imagine in the above sample history B0 did not exist,
origin/master started at B1, moved to B2 and then B, and you forked
your topic at origin/master^ when origin/master was B1; the shape of
the history would be the same as above, without B0, and the parent
of B1 is what git merge-base origin/master topic
correctly finds,
but the --fork-point
mode will not, because it is not one of the
commits that used to be at the tip of origin/master).また、あなたが--fork-point
モードを使用するリモートトラッキングブランチはあなたのトピックがその先端から分岐したものでなければなりません。tipよりも古いコミットから分岐した場合、このモードでは分岐点が見つかりません(上のサンプル履歴ではB0は存在せず、origin / masterはB1で始まり、B2に移動してからBに移動し、トピックを分岐しました) origin / masterがB1の場合、履歴の形は上と同じですが、B0はなく、B1の親はgit merge-base origin/master topic
正しく見つかり--fork-point
ますが、モードはそうではありません。以前はオリジン/マスターの先端にあったことをコミットします。
See alsoまた見なさい
git-rev-list[1], git-show-branch[1], git-merge[1]git-rev-list [1]、git-show-branch [1]、git-merge [1]
GIT
Part of the git[1] suite一部のgit [1]スイート
関連記事
- write-tree
- verify-pack
- update-ref
- update-index
- symbolic-ref
- show-ref
- rev-parse
- rev-list
- read-tree
- ls-files
- hash-object
- for-each-ref
- diff-index
- count-objects
- commit-tree
- checkout-index
- check-ignore
- cat-file
- bundle
- archive
- instaweb
- filter-branch
- reflog
- fsck
- gc
- clean
- Workflows
- Tutorial
- Revisions
- gitmodules
- gitignore
- githooks
- Glossary
- Everyday Git
- gitattributes
- update-server-info
- daemon
- fast-import
- svn
- request-pull
- send-email
- format-patch
- am
- grep
- blame
- bisect
- revert
- rebase
- cherry-pick
- apply
- describe
- shortlog
- show
- submodule
- remote
- push
- pull
- fetch
- worktree
- tag
- stash
- log
- mergetool
- merge
- checkout
- branch
- mv
- rm
- reset
- commit
- diff
- status
- add
- clone
- init
- help
- config
- git
スポンサーリンク