There was one branch, master. The last commit in this github branch was not very good, so I created a new branch (second) based on the previous Master commit. Now I need to save the changes I made to the second branch (second) and merge it into the master branch, overwriting all the files on it. How to do it? enter image description here

  • 3
    The illustration is fire. - Nick Volynkin

1 answer 1

If the repository on GitHub is only yours and nobody else uses it

And if you just want to discard the changes from the last commit, which is “not very”.

You can “rearrange” the master branch to the same commit that second watching.

 git checkout master git reset --hard second 

And then send the changes to github.

 git push -f origin master 

The last commit, which is “not very”, will remain in the repository for a while and will be available via git reflog , after which it will be permanently deleted.

If the repository is not just yours

Then you cannot rewrite the master branch. We will roll back unwanted commits with git revert .

 git checkout master git revert HEAD 

A new commit will appear in the master branch, undoing changes made to the undesirable. As a result, the state of the files will be like in the commit where the branches split.

Now you can transfer the result from the second branch.

 git merge second 

Why can not you just hold up?

Because changes from an undesirable kommit will not disappear anywhere. They need to be rolled back explicitly.