简体   繁体   中英

Merge branches with no “simultaneous” changes and keep branch structure

When I have a branch like this:

      A---B---C topic
     /
D---E---F---G master

and merge topic back to master, I'll get this:

      A---B---C topic
     /         \
D---E---F---G---H master

Now, even if I remove the topic branch (let's say it was just a local development branch and I only push master ) I'll still have the information, that there was a feature implemented starting at E and finished at H .

Is it possible to keep the same kind of imformation even, when there were no simultaneous commits on the master branch, while I was working on the topic branch? For example:

      A---B---C topic
     /
D---E master

If I merge now, I'll get this:

D---E---A---B---C master/topic

If I remove the topic branch, I'll have no information in the future, where the feature implemented in the topic branch was finished. And even if I keep the branch, I don't know where it started.

I would prefer to keep both parents and have something like this:

      A---B---C topic
     /         \
D---E-----------F master

I think this is the default behavior of svn. Can I achieve the same with git?

Yes, using the --no-ff flag will create a merge commit even if the merge resolves to a fast-forward case. Example (assuming you started at C ):

git checkout E
git merge --no-ff C

More information is available at the git-merge(1) documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM