Moving some commits to a feature branch but leavin

2019-07-13 17:32发布

问题:

I am not sure if I can do anything about this and it is not a huge hardship to leave it as it is.

I did try to fix things by following steps on other SO topics etc. and ended up loosing all my help revision commits and files.

Things are a little messy and I will try to explain. The history is OK up to a certain point:

Removing unused resource ID values from resource.h

Can you see that towards the bottom of the screenshot of the log?

Since that time, the majority of the commits are help file revisions:

  • Deleting help topics and redundant images
  • Revising help topics and images
  • Adding new help topics and images

But it gets complicated because with that big chunk of help revision commits I have some code change commits. Eg:

Added SetLoggingPath to CMSATools.

Revised CChristianLifeMinistryUtils::FillStudentsListBox method. Now it reads the students from the publishers database.

The plot thickens, for a small handful of them, eg:

Add Help menu to CPublishersDatabaseDlg.

In those cases the commit is a combination of code changes and help revision changes:

Added OnHelpHelp menu handler.

Started writing Help/HelpPublisherDatabase.html help topic.

The primary issue:

Beginning at this commit in the master branch: Removing unused resource ID values from resource.h can I make a new feature branch called: help-revisions and then, move the commits from master to the feature branch?

If it is possible, I am assuming we would need to move just the commits that are purely help revisions. I am not sure how to handle the commits that are a mixture of help changes and code changes.

So, ideally I am hoping to split out all the help revisions into a feature branch so that it can be merged in to the master and look better in the log. Leaving the code tweak commits alone in the master in an appropriate position.

The related matter is the cause of some of this. But I am not going to discuss that here after all.

As mentioned, I am just curious as to know if it is possible to improve the history I have as indicated.

I am a lone developer so do not have to worry about other individuals repositories.

Thanks for your help and time.

Update

I have given the rebase a go. I marked all the commits I wanted to split as edit. Then I started the rebase. I ticked edit/split and revised them as I needed until it completed.

Now my log looks like this:

Underneath, it looks like this:

So how do I get rid of that section? I have to fix that before I create the feature branch and do the cherry picking.

So, at the top I now have a new set of all the commits including the split ones.

Got it - did a force push of master branch.

回答1:

This can be accomplished by a mixture of cherry-picking and rebasing.

  1. Create a new feature branch which is before all your commits which are affected. Then select all commits you want to have on that new feature branch and select "Cherry-pick commits". After that you have a branch where only the selected commits are on.

  2. Switch back to the previous branch and do a rebase on the parent of the newly created branch (you will need to enabled "force"). Now mark all cherry-picked commits again and select skip and start the rebase. Now, this branch does not contain the cherry-picked branches any more.



标签: tortoisegit