To get a history of merge commits made in the current branch, use the following command:

git log --merges
Answer from mkrufky on Stack Overflow
🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently.
🌐
Gfscott
gfscott.com › blog › merge-git-repos-and-keep-commit-history
How to merge multiple Git repos and keep their commit history / Graham F. Scott
By default, a successful merge command creates a commit. I like using the --no-commit flag so I can confirm the new file structure before committing the changes, but it's optional. # ./everything # youtube/monorepo-prep = <remote repo name>/<branch name> # --allow-unrelated-histories = It's OK to smoosh these repos together # --no-commit = (Optional) Stage instead of committing $ git merge youtube/monorepo-prep --allow-unrelated-histories --no-commit
🌐
LabEx
labex.io › tutorials › git-how-to-view-commit-history-after-a-merge-in-git-417935
How to view commit history after a merge in Git | LabEx
Merge commits can be easily identified in the commit history, as they have two or more parent commits. You can use the git log command with the --graph option to visualize the commit history and locate the merge commits:
🌐
Medium
alex-v.medium.com › how-to-merge-git-repositories-and-keep-history-587f973f06a0
How to merge Git repositories and keep history | by AlexV | Medium
April 16, 2025 - cd path/to/your/project git checkout <desired-branch> git filter-repo --path path/to/the/code/ --to-subdirectory-filter <name of your subdirectory> Now that you’ve stored the history of the code you want to merge into a subdirectory.
🌐
Useful
useful.codes › viewing-the-git-merge-history
Viewing the Git Merge History | Useful Codes
While command-line tools are powerful, visualizing merge history can provide a clearer understanding of how branches have interacted over time. Here are some popular tools that can help you visualize merge history: gitk is a graphical history viewer for Git repositories.
🌐
Reddit
reddit.com › r/git › best way to merge history back into a repo that wasn't cloned
r/git on Reddit: Best way to merge history back into a repo that wasn't cloned
October 3, 2024 -

Situation:

  • My company purchased the code and rights to an existing software product in a acquision.

  • An outsourced dev firm "forked" the original GitHub repo for the initial owners by exporting the current HEAD, and committing it to a new GitHub repo as the initial commit.

  • Several additional commits, branches, and merges have happened since then in the new repo

Goal:

Have one repo with the full history from the original repo plus all the changes from the new repo.

I have access to, but not ownership of, the source repo.

How can I merge the history back into the repository?

🌐
Reddit
reddit.com › r/git › git merge is merging the entire commit history
r/git on Reddit: Git merge is merging the entire commit history
May 14, 2023 -

Hi everyone, I'm having trouble understanding why my git merge is rebasing and the entire commit history of the branch that is being merged is getting added to the branch I'm merging into...

[git-test]$ git reflog
16b6ee0 (HEAD -> main, feature-a) HEAD@{0}: merge feature-a: Fast-forward
beae265 HEAD@{1}: checkout: moving from feature-a to main
16b6ee0 (HEAD -> main, feature-a) HEAD@{2}: commit: imported feature a in index
000b168 HEAD@{3}: commit: coded feature a
00b2791 HEAD@{4}: commit: initialised empty feature-a file
beae265 HEAD@{5}: checkout: moving from main to feature-a
beae265 HEAD@{6}: commit: coded index file
d0e5c98 HEAD@{7}: commit (initial): created index file

[git-test]$ git log --graph  --oneline --all
* 16b6ee0 (HEAD -> main, feature-a) imported feature a in index
* 000b168 coded feature a
* 00b2791 initialised empty feature-a file
* beae265 coded index file
* d0e5c98 created index file
Find elsewhere
🌐
Quora
quora.com › What-happens-to-commit-history-when-merging-two-branches-using-Git
What happens to commit history when merging two branches using Git? - Quora
Answer (1 of 2): Merge creates a new commit which has pointers to parent commits as text references (the SHA-1 identifier of each parent is stored as text). Visualization tools typically render the first parent from metadata as the original parent and other parents are rendered as “merged ...
Top answer
1 of 2
63

It looks like the first merge was a fast-forward, and the second one was a three-way merge.

Explanation

Git has two versions of merge: fast-forward and three-way. (There are other versions, but that is not what happened here.) The default behavior is to do a fast-forward merge when possible, and otherwise do a three-way merge.

A fast-forward merge can take place when the commit that is being merged has the current position of the branch in its history (you can force this behavior with the option --ff-only, which will cause the merge to fail when fast-forward is impossible). For example:

A - B - C - D <-master
             \
              E - F - G <- branch-a

Executing git merge (with default settings) will result in

A - B - C - D - E - F - G <- branch-a <-master

You will also not get a chance to edit the merge commit because there is none.

A three-way merge when your other branch diverges from master (not just ahead):

A - B - C - D  - E - F - G <-master
                  \
                   E1 - E2 <- branch-b

In this case, Git cannot just move the pointer of master from G to E2 because that will get rid of the changes that were made in F and G. When a three-way merge happens, it creates a commit that has two parents, and also has a commit message. Now, master can be moved to this commit. (Notice that in this situation, master and branch-b do NOT point to the same commit.

A - B - C - D  - E - F - G - H <-master
                  \       /
                   E1 - E2 <- branch-b

If you want to have a linear history then you need to use rebase, but be forewarned that if anybody else has seen your branch commits this may lead to issues that are beyond the scope of this answer. Using rebase will involve two steps, rebasing and then fast-forward merge. So, instead of merging you first execute the following while on branch-b, git rebase master. This creates new commits that are copies of the old commits, i.e., the same change-set, author information and message, but new committer information and parent history. (I call the commits E1' and E2' in the illustration to indicate that they are just copies.) The old commits will exist until they are garbage collected, but will not be reachable unless you look at the reflog.)

A - B - C - D  - E - F - G <-master
                  \       \
                   E1 - E2 \ 
                            E1' - E2' <- branch-b

Executing git checkout master; git merge --ff-only branch-b will now fast-forward your changes into master, thereby giving you a linear history.

A - B - C - D  - E - F - G - E1' -E2' <-master <- branch-b
2 of 2
12

Use rebase instead of merge. From the tutorial:

If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.

I imagine that the changes from your Branch-B cannot be merged using fast-forward merging into the master. In such cases a three-way-merge is done:

Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent.

I would always rebase my commits before commiting them into the master to keep the linear history.

🌐
GoPa
faun.dev › c › stories › d9nich › advanced-git-merge-history-diffs
Advanced GIT — Merge, History & Diffs
September 14, 2022 - GIT can remember how you solved the previous merge conflict and in the next commit reuse the same resolution.
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
When creating a merge commit Git will attempt to auto magically merge the separate histories for you. If Git encounters a piece of data that is changed in both histories it will be unable to automatically combine them.
🌐
Medium
medium.com › @checko › merging-two-git-repositories-into-one-preserving-the-git-history-4e20d3fafa4e
Merging two Git repositories into one preserving the git history | by Nyah Check | Medium
September 26, 2018 - This is because git merge allows the merging of two branches that have a common base by default preventing parallel git histories from existing in the same project.
🌐
Salesforce
trailhead.salesforce.com › learn › git and github basics › work with your history in git
Understand Your Git History and Version Control - Trailhead
As you create new commits, they reference the previous commit as its parent. This reference point is very important. This linear, parent/child relationship creates a consistent history and is what enables Git to merge branches together.
🌐
Medium
supremecodr.medium.com › how-to-cleanup-git-merge-history-using-rebase-dbb78070b946
Git rebase — How to clean merge history log and squash commits | by Sami Samiuddin | Medium
November 14, 2025 - How would this look if the person ... This is a very simple example but as soon as you start getting more branches and commits, git log quickly becomes a mess to look at....
🌐
Microsoft Learn
learn.microsoft.com › en-us › devops › develop › git › understand-git-history
Understand Git history - Azure DevOps | Microsoft Learn
The graph structure of history becomes visible when there's a merge. Git creates a new commit when the branch is merged into another branch. This is a merge commit. There aren't any changes included this merge commit since there were no conflicts.
🌐
Autorabit
knowledgebase.autorabit.com › product-guides › arm › arm-features › version-control › ez-merge › git-commit-history-and-merge-operations-basics
Git Commit History and Merge Operations Basics | AutoRABIT Knowledge Base
April 15, 2025 - Why Does Git Allow Duplicate Commits During Merges? Git is designed to preserve a complete and traceable commit history. Even when two branches include identical changes, Git may create a new merge commit each time they are integrated.
🌐
Medium
medium.com › @codenova › understanding-git-merge-keep-your-project-history-clean-fd69db1e1dbe
🔄 Understanding Git Merge: Keep Your Project History Clean 🔄 | by Codenova | Medium
October 17, 2024 - Git creates a new “merge commit” that ties together the changes from both branches. 🔑 Pro Tip: Use three-way merges to handle complex changes but ensure to resolve conflicts carefully to avoid breaking the code. This option combines all commits from a branch into a single commit before merging. This helps avoid cluttered commit history, especially when there are multiple small, incremental changes.
🌐
Jeff Kreeftmeijer
jeffkreeftmeijer.com › git-combine
Combine Git repositories with unrelated histories
August 9, 2021 - To combine the two repositories, first add the second repository as a remote to the first. Then, run git fetch to fetch its branch information: ... Then, with the remote set up, merge the second repository’s history into the first by using the --allow-unrelated-histories flag:
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-merge
Git Merge - GeeksforGeeks
May 9, 2026 - Git Merge combines changes from different branches into a single branch, integrating work while preserving history.