branching a branch from a particular commit and migrating subshot commits

Asked

Viewed 58 times

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 at the root of the project, so I opened the Gitbook Editor.

But the Gitbook Editor thought that he should go back to Branch Master on his own, and I didn’t see that he checked out for master, thus making a few edits to master.

I’m not sure how to migrate edits from a certain commit to the end of the current master pair to the `master-gitbook branch"

My tree actually looks like this:

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

In case how do I need to make the commits from M4 to M10 belong to the branch master-gitbook so that I can continue my work?

And since I can’t stop work, assuming I have a new commit like below

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

make commits from M4 to M10 belonging to the new branch and keep M1 in the branch masterfarm that they stay like this:

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

  • M4 commits onwards have already been "pushed" to the server? Or have they remained only local?

  • @Charlesrobertocanato, consider as places.

1 answer

2

One can do the fast-forward master-gitbook for m10 and then remove the commits m4 to m10 of master. Use the commands below (overriding mX by the SHA-1 hash of the respective commit):

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

In the text editor that opens, delete all commit lines m4 to m10. Only the lines should remain m11 onward.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.