Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pages/common/git-merge-base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# git merge-base

> Find a common ancestor of two commits.
> More information: <https://git-scm.com/docs/git-merge-base>.

- Print the best common ancestor of two commits:

`git merge-base {{commit_1}} {{commit_2}}`

- Output all best common ancestors of two commits:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best can only be 1.

Suggested change
- Output all best common ancestors of two commits:
- Print all merge bases for two commits:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the way git weighs merge bases, there actually can be two "best" ones, which means two of the same quality. But I agree that the wording is confusing, so maybe "all suitable" should be used?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


`git merge-base --all {{commit_1}} {{commit_2}}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`git merge-base --all {{commit_1}} {{commit_2}}`
`git merge-base --all {{commit1}} {{commit2}}`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not commit_hash instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the git subcommand pages are not consistent in this matter, but the majority uses just commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the git subcommand pages are not consistent in this matter, but the majority uses just commit.

It means that consistency should be fixed. For instance we can write script to do that like in #9578 PR.


- Check if a commit is an ancestor of a specific commit:

`git merge-base --is-ancestor {{ancestor_commit}} {{commit}}`