branching a branch of a given commit and migrating subsequent commits

3

I was updating a repository, creating its documentation, so I created a new branch called master-guibook a "./docs" directory and a "book.json" file in the project root, so I opened the Gitbook Editor.

But the Gitbook Editor felt that he should go back to Branch Master on his own, and I did not see him checkout for the master, doing some editing on the master.

I'm not sure how to migrate the edits of a certain commit to the end of the current master pair for the 'master-gitbook' branch

My tree currently looks like this:

master-gitbook /branch-master-gitbook-porem-vazio / master m1---m2---m3---m4---m5---m6---m7---m8---m9---m10

In the case how do I make commits from m4 through m10 to belong to branch master-gitbook so I can continue my work?

And since I can not stop the job, assuming I have a new commit as below

master-gitbook /branch-master-gitbook-porem-vazio / master m1---m2---m3---m4---m5---m6---m7---m8---m9---m10---m11

Make the commits from m4 to m10 belonging to the new branch and keep m1 in the branch master fazend as follows:

master-gitbook /---m4---m5---m6---m7---m8---m9---m10 / master m1---m2---m3---m11

    
asked by anonymous 31.08.2016 / 22:59

1 answer

2

You can fast-forward from master-gitbook to m10 and then remove commits m4 to m10 from master . Use the following commands (substituting% of the commit with the SHA-1 hash):

git checkout master-gitbook
git merge m10
git checkout master
git rebase -i m3

In the text editor that will open, delete all lines for commits mX to m4 . There should be only the lines m10 on.

Note: The m11 command will only work as if the git merge m10 branch is still in master-gitbook . Otherwise, a merge commit is created instead of a fast-forward or you should use m3 instead of rebase .

    
12.10.2016 / 18:43