I have a master branch and I checkout a new branch named test_branch for my daily work.I did lots of redundant "git commit" in test_branch so there are many history commit log in test_branch.When I merge test_branch to master , I don't want these history log to be merged to the master.How can I do to merge only the source files?
-
What do you mean by "commit logs"? – Noufal Ibrahim Jan 21 '15 at 06:39
-
@ Noufal Ibrahim I mean I do a lot of "git commit" in test_branch and many of them are useless so I don't want this commit history show in my master branch.I just want merge the change between source code – ctxrr Jan 21 '15 at 06:41
3 Answers
You do:
git checkout master
git merge --squash test_branch
This gives you one new version on master, and this will NOT be a merge when committing it.

- 17,357
- 9
- 82
- 98
-
Please understand the implications of doing this and how the history of project changes in both cases before doing this. – Noufal Ibrahim Jan 21 '15 at 07:41
-
Note that this is effectively the same as doing `git checkout master` and `git checkout test_branch -- .` in the root of your repository. – Sascha Wolf Jan 21 '15 at 10:47
The git merge
command merges commits. It doesn't merge files. The development path on your test_branch
will become a part of your project history. If you're not satisfied with it, you should do a rebase -i
on that branch and edit to the clean up the history so that it looks like what you want it to and then merge the branch. Iy you don't care for the history, you can squash all the commits on test_branch
into a single commit onto master using git merge --squash
. This will, however, destroy the fine grained history and will not really gain you anything.
Many version control systems consider a branch a completely separate thing from the main development line and the only thing the main branch can see after a merge is the merge itself. With git, due to the lightweight nature of its branches, the development history of the branch merged into your main one will also be visible.

- 71,383
- 13
- 135
- 169
You want to "squash" or "rebase" your commits. You can read about the details of how to do that here: Squash my last X commits together using Git

- 1
- 1

- 239,568
- 38
- 324
- 436