问题
Goal: keep a clean history of master, whilst also keeping the intermediary commits.
For instance, let's start with a master branch:
M1 --- M2 --- M3
              ^                  
              master
I work on a feature/bug/whatever on a new branch:
M1 --- M2 --- M3
              ^  \
              |   \- F1 --- F2 -- F3
              |                   ^
              master              feature
And when I merge into master, I want M3 to be the parent, but also keep the "iterations" you took to reach from M3 to the new commit. This can be done with merge --no-ff:
M1 --- M2 --- M3 ----------------------- M4
                 \                    /  ^
                  \- F1 --- F2 -- F3-/   master
                                  ^
                                 feature
Which is almost what I had in mind. The problem I have is that for git, as far as I can tell, both M3 and F3 are "equal" parents of M4, now both part of branch master.
What I want is to be able the show (with git log) the master branch without the feature branch (F1-F3) to have a cleaner view over the branch. ideally this would be default. But also be able to show the F1 F3 commits to view the more "detailed" history when needed.
Is there a way to have this, or something close to this in git?
回答1:
How about
git log --first-parent master
To quote the manual
Follow only the first parent commit upon seeing a merge commit. This option can give a better overview when viewing the evolution of a particular topic branch, because merges into a topic branch tend to be only about adjusting to updated upstream from time to time, and this option allows you to ignore the individual commits brought in to your history by such a merge.
来源:https://stackoverflow.com/questions/44435485/clean-master-branch-but-also-detailed-record-of-intermediary-commits