To go to work with one of the old commits, I used this scheme:

git checkout -b имя-новой-ветки aaaaaa (wt) (i) A - B - C - D ↑ ↑ new master (HEAD) 

Taken from this answer .

But now I need to merge with the master branch, so as to be after commit D , and come to this state. Since the work is still being done in the master branch.

  ---------- M / \ A - B - C - D - H ↑ master (HEAD) 

How to do it?

  • М commit in your branch of a feature is made or in master ? - Nick Volynkin

2 answers 2

You did everything right. Suppose you just made a new commit F * in the feature branch:

  (HEAD) new ↓ --------- F / A - B - C - D ↑ master 

* - I do not use the letter M here so that it gets to the merge commit.

The simplest thing is to switch to the master branch and give the command to merge (merge) into it of your branch.

 git checkout master git merge feature 

If the same strings change both in F and in the chain B , C , D , then there will be a merge conflict. It will need to be resolved by manually selecting the desired line from both options.

Result:

  • A new merge commit with two ancestors will appear in the master : D and F
  • The new branch will remain untouched.
  new ↓ --------- F - / \ A - B - C - D - M ↑ master (HEAD) 

Loading ...

  • one
    In the evening I will rebase about the rebase . Remind me if that. - Nick Volynkin
  • OK thanks. And if I don’t want to resolve it manually, I somehow can say to the gita that in conflict D and F, F is always right? - Pavel
  • one
    git merge -s theirs git-scm.com/docs/merge-strategies - Nick Volynkin
  • 2
    @Pavel, but this is a risky practice - you can keep in mind one place, and git will silently fix others for you. More reliably with your hands to resolve conflicts. - Nick Volynkin
  • one
    UPD: No, not this evening, no strength left. ) - Nick Volynkin

Confused however. If you want to make any changes on the basis of a specific commit, you can create a new branch from the commit, make the necessary changes, make a commit into the branch and then simply merge the branch with master.