How to deal with Git break?

Let's say that in our Git repository we worked on the master branch for some time. Then most of us started working with the coolfeature branch, while several developers continued on to master .

Now the developers who worked on master have lost interest, and what they have developed since we are forked is not very important. But we would like the main branch of development to be called master again. It’s clear that we would like the tree to look something like this:

 *--master--X ----master \ / --coolfeature-- 

What is the easiest way to achieve this? We really do not want to try to combine the coolfeature, and we are happy that the fixation marked X is completely meaningless.

+7
source share
2 answers

Force push with a new main branch.

 git push -f origin master 

Other people extract the code and do a reset

 git fetch origin master git reset --hard origin/master 
+3
source

How would I do this and not force push:

  • create a tag to commit X that you are not interested in. (You will see why in a minute.
  • Do a git revert all commits on the main branch since you have separated the cold environment. This returns the repository to the state that it was when you were branching, but it does not rewrite the history, so no one repository will break if they did not receive the note.
  • Combine coolfeature with the master.

The tagging point X is the point mark before making all changes. Tags are cheap, and at some point you may need to know at what point you canceled commits and made such changes.

+2
source

All Articles