Git drain flattening

If I work in multiple branches for one function, I use git pull branch1 branch2 branch3 to pull all the changes to my main branch. However, all commit logs of each branch are also copied. How to smooth the commit log to a single message?

+39
git git-pull git-merge git-push
Apr 23 '09 at 22:08
source share
3 answers

You can use interactive rebase and "squash" commits - see also Git A ready-made tutorial on distributing through rebase . Sorry to just dump the link to you, but this is a pretty thorough tutorial. Oh, and that will do a great job of merging you too.

+24
Apr 23 '09 at 23:06
source share

"git merge --squash" (after "git fetch"; "git pull" is just fetch + merge, pehaps also allows the -squash option) whatever you want.

From git-merge (1) :

- zucchini

Create a working tree and index state as if a real merge had occurred, but don't actually commit or move HEAD, or write $GIT_DIR/MERGE_HEAD to invoke the following git commit command to create a merge commit. This allows you to create a single commit on top of the current branch, the effect of which coincides with the union of another branch (or more in the case of octopuses).

+69
Apr 24 '09 at 18:26
source share

As Brian White said, the problem with git merge --squash is that it does not give you any visible link and therefore is not tracked back to the branch (or individual changes) that you merged into.

It can be seen (if you consider it as a git log --graph ), the important branch that was merged back is no different from the experimental branch that you encountered and happily drop it. Both just hang there, not attached to anything. I personally want to know that some branch has been merged, so I know that the work is done.

The solution that works for me is to use merging with the option without quick access.

 git merge --no-ff somebranch -m "my commit message" 

This forces git to create a single commit with all the branch changes enabled, you can set the commit message yourself (if you want), but most importantly, it links the new commit back to the branch it just merged into. This clearly shows that work on this branch has been completed, but also allows you to track back to view the details of individual commits from the combined branch.

Here is an example where very simple branches with one and two commits, respectively, were merged back into master. Subsequently, I removed the branch tags for the merged branches, however the branch name can still be seen in the merge commit message. The branch name should summarize the changes, and if you want to know exactly what changes are contained in it, you can track it to individual commits. This approach seems to work well for simple projects.

Note. I had to manually draw one of the connectors because it was so blue that it was barely noticeable.

git log output

+7
Sep 02 '15 at 11:19
source share



All Articles