Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a Git discontinuity?

Tags:

git

Let's say that in our Git repository, we worked on branch master for a while. Then, most of us started working on coolfeature branch, while a few developers continued on master.

Now, the developers who worked on master have lost interest, and what they developed since we forked isn't very important. But we'd like the main development branch to be called master again. Conceptually, we'd basically like the tree to look something like this:

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

What's the easiest way to achieve this? We really don't want to try and merge coolfeature, and we're happy for the commit marked X to be totally meaningless.

like image 844
Steve Bennett Avatar asked Sep 05 '12 06:09

Steve Bennett


2 Answers

Perform a force push with the new master branch.

git push -f origin master

Other people fetch the code, and perform a reset

git fetch origin master
git reset --hard origin/master
like image 114
linquize Avatar answered Nov 04 '22 13:11

linquize


The way I would do this and avoid doing a forced push:

  1. create a tag for the commit X that you don't care about. (You'll see why in a minute.
  2. Perform a git revert of all the commits on the master branch since you branched off coolfeature. This puts the repository back to the state it was at the time you forked, but it doesn't rewrite history, so nobody's repository gets broken if they didn't get the memo.
  3. Merge coolfeature onto master.

The point about tagging X is to mark the point before you did all the changes. Tags are cheap, and at some point you might want to know the point at which you backed out commits and made such a change.

like image 31
Abizern Avatar answered Nov 04 '22 15:11

Abizern