问题
I'm using Git for code versioning.
I have a development branch on which i'm doing all the dirty development.
Every time I publish a production version to the world, I want to put it under my master branch.
The problem is that whenever I merge development and master, master receive all development history.
I want to keep everything clean so the branches will look like this:
development
"init commit"
"developing"
"Version 1.0"
"bug fixing"
"bug fixing"
"Version 1.1"
master
"Version 1.0"
"Version 1.1"
Is it possible? and if so, how ?
UPDATE I tried to use Gauthier answer but it doesn't worked as I wanted.
The steps I took was as followed: 1. created an init commit in master 2. switched to development. 3. added few commits to development. 4. checkout master 5. git merge development --no-ff
The merge was successful but when i'm looking on high level at my repository, I see that in my master branch I have all the history of the development branch, while I wanted to have only init-----version 1.0.
This is screen shots of how it looks:
development branch:

master branch:

回答1:
Do you know about --no-ff
?
You currently have:
o init commit
|
o developing
|
o Version 1.0
|
o bug fixing
|
o bug fixing
|
o Version 1.1
|
o Version 1.0
|
o Version 1.1 - development - master
(time going downwards as in your example, instead of what git log
and gitk
do)
My guess is that you are unhappy with master
because everything gets directly there, at the same level.
If you would be happy with:
o init commit
|\
| o developing
|/
o Merge branch 'development' - Version 1.0
|\
| o bug fixing
| |
| o bug fixing
|/
o Merge branch 'development' - Version 1.1 - development - master
then when you want to release what you have in development
, merge to master
with --no-ff
, and tag:
$ git checkout master
$ git merge development --no-ff
$ git tag "v1.0"
Note that you should consider working in branches named after the feature you are working on, rather than everything in development
. This would lead to better merge messages, such as "Merge branch 'killer_feature'". Maybe that's what you have in development
already, in that case, sorry.
回答2:
This is not possible in the same repository. All branches share the same common history. Git branch is not a separate copy of your commits, but a lightweight solution to re-use as much as possible of the existing data.
Solutions:
However, it is still possible to create new "clean" commit for the master, which squeezes many "dirty" development commits. See this solution.
If you want to have a "clean" repository, consider creating another, public, repository. You can just copy over each new release and submit a commit for it.
回答3:
First of all let me say that you should not do this :) you can use --squash parameter of git merge and re-commit the changes in one commit with the message you want. At this point you will have to reset --hard your development branch to master branch to avoid merging the same changes next time you merge development branch into master branch.
Second approach would be to avoid writing commit msgs like "Make changes to the code" or squash your temporary commits once the feature/work is complete on development branch and then merge to master.
P.S. git log master --merges will give you the history of master the way you want it and you would not lose your git history (given that your merge messages are ok and you use --no-ff when merging)
来源:https://stackoverflow.com/questions/29968041/git-merging-development-branch-with-master-for-production-versions