Create a git branch from the selected commits to another branch

I created a "feature" from the branch and worked for a long time. Then I typed in the last commit of the master branch and reinstalled my feature branch, which ends on top of it. Then I combined the “function” into a wizard. However, I forgot about the merger and continued to enter the "feature". I want those commits in a new branch now, so now I would like to create another branch "feature_2", which is based on a commit in the branch "feature" since the last merge in master. Any suggestions?

+3
source share
1 answer

Given that:

  • feature master
  • - .
x--x--x (master)
       \
        y--y--y (feature)

:

  • git checkout feature
  • git checkout -b feature2
  • git branch -f feature master
    ( master feature)
x--x--x (master, feature)
       \
        y--y--y (feature2)

master feature ( reset master), feature2 ( feature , reset master)


OP Chip Castle :

, , , .
SHA , , . ?

, :

x--x--x--y'--y' (master, updated after a fetch from other repo)
       \
        y'--y'--y--y (feature, with y' being already merged, 
                      and y being the commits I need)

: .

+1

Source: https://habr.com/ru/post/1760003/


All Articles