Git Shows the Entire History of a Branch by Default
The original poster says
I can see all the commits from the FEATURE branch.
What did I do wrong?
This is expected behavior in Git. When you merge a branch B into another branch A, the history of B becomes a part of the history of A, so of course B's commits would also show up in the history of A.
By default, Git shows the entire history of branches, including commits that have been merged into them.
This is true whether you do a fast-forward merge or not. The difference here between a fast-forward merge and a merge done with --no-ff
is that --no-ff
will force the creation of a merge-commit, even when a simple fast-forward (without a merge commit) would have been possible.
Either way, however, you would still normally see the commit's of all of the branches that have been merged into the current one.
Hiding the History of Merged Commits
If you don't want to see the history of merged commits, you can hide them from the log output by passing in the --first-parent
option
$ git log --oneline --graph --first-parent
* e156455 Git 2.0 (HEAD, tag: v2.0.0, https/master)
* 4a28f16 Update draft release notes to 2.0
* 8ced8e4 Git 2.0-rc4 (tag: v2.0.0-rc4)
* 3054c66 RelNotes/2.0.0.txt: Fix several grammar issu
* b2c851a Revert "Merge branch 'jc/graduate-remote-hg-
* 00a5b79 Merge branch 'jc/graduate-remote-hg-bzr' (ea
* df43b41 Merge branch 'rh/prompt-pcmode-avoid-eval-on
* 7dde48e Merge branch 'lt/request-pull'
* 5714722 Merge branch 'jl/use-vsatisfy-correctly-for-
* c29bf4a Merge git://github.com/git-l10n/git-po
* 3fc2aea Merge branch 'kb/fast-hashmap'
* 6308767 Merge branch 'fc/prompt-zsh-read-from-file'
Compare that with the output of viewing the whole history for a branch
$ git log --oneline --graph
* e156455 Git 2.0 (HEAD, tag: v2.0.0, https/master)
* 4a28f16 Update draft release notes to 2.0
* 8ced8e4 Git 2.0-rc4 (tag: v2.0.0-rc4)
* 3054c66 RelNotes/2.0.0.txt: Fix several grammar issues, notably a lack
* b2c851a Revert "Merge branch 'jc/graduate-remote-hg-bzr' (early part)"
* 00a5b79 Merge branch 'jc/graduate-remote-hg-bzr' (early part)
|\
| * 896ba14 remote-helpers: point at their upstream repositories
| * 0311086 contrib: remote-helpers: add move warnings (v2.0)
| * 10e1fee Revert "Merge branch 'fc/transport-helper-sync-error-fix'"
* | df43b41 Merge branch 'rh/prompt-pcmode-avoid-eval-on-refname'
|\ \
| * | 1e4119c git-prompt.sh: don't assume the shell expands the value of
* | | 7dde48e Merge branch 'lt/request-pull'
|\ \ \
| * | | d952cbb request-pull: resurrect for-linus -> tags/for-linus DWIM
* | | | 5714722 Merge branch 'jl/use-vsatisfy-correctly-for-2.0'
|\ \ \ \
| * | | | b3f0c5c git-gui: tolerate major version changes when comparing
* | | | | c29bf4a Merge git://github.com/git-l10n/git-po
|\ \ \ \ \
| * | | | | a6e8883 fr: a lot of good fixups
* | | | | | 3fc2aea Merge branch 'kb/fast-hashmap'
|\ \ \ \ \ \
| |/ / / / /
|/| | | | |
| * | | | | c2538fd Documentation/technical/api-hashmap: remove source hi
* | | | | | 6308767 Merge branch 'fc/prompt-zsh-read-from-file'
Keeping a Simpler History by Avoiding Merge Commits
When Git users talk about maintaining a "clean history", they're often referring to avoiding the creation of merge commits. This is often the case when frequently updating a feature branch with new changes from the master branch. People want to avoid merge commits in these cases because they don't add much additional informational value when you're looking at the log for the feature branch, and end up being "clutter", "junk", and "noise", making it harder to see the more important changes that have been made.
To avoid that kind of situation, Git users will often rebase the feature branch on top of an upstream branch like master, which will update the feature branch (just like a merge would), but without creating a merge commit. It's in this way that Git users will "keep a clean history", by avoiding the creation of unnecessary merge commits, and thus maintaining a simpler, easier to understand commit history.
See Also
For more information on fast-forward merges vs non-fast-forward merges, see