Removing features and merging those changes back can be painful. Here is how it worked for me.\
tl;dr
Show archive.org snapshot
: Before merging back: reinstate reverted features in a temporary branch, then merge that branch.
Consider your team has been working on several features in a branch, made many changes over time and thus several commits for each feature.\
Now your client wants you to deploy while there are still stories that were rejected previously and can't be deployed.
In this situation you basically have 3 options:
master
or production
branch)While it does not feel right to invest time into removing features that will be finished in the near future and you'd prefer the first option, it's sometimes just not possible and you must invest time on one of the other options.
Option 2 sometimes is not feasible so let's say you went with number 3 and removed features. When you merge those changes back after deployment, you may run into conflicts -- especially if your team continued working on the features you've been reverting for the last 2 days.
To keep it as little annoying as possible, you should keep a few things in mind:
git rebase -i
to squash all reverts into one commit. This will make it a lot easier to restore functionality later.master
into your branch regularly, especially when you have multiple teams preparing for deployment and adding their changes there.master
or production
, check some spots manually on your machine.As said before, your team probably continued working on the features you removed in a separate branch. Merging back may be ugly but this is where your few commits come in handy.
You have 2 options to get the deployed state into your team branch and previous features back:
Merge back master
into your team's branch, then revert your "Remove XY" commits.
: This may seem fast but can introduce more conflicts than necessary. If there are lots of conflicting files, try the next approach:
Branch off, e.g. into master-with-reinstated-features
, revert your "remove" commits there, then merge that branch into your team branch.
: This can still give you some conflicts but they were significantly smaller for me on the project I did this on. Basically it's not much slower than the above but can save you lots of trouble.
Resolving conflicts can be tricky. If the diff is too unreadable, you can cheat by doing a git show master:path/to/file
and see what the deployed state looks like -- it's probably correct. If your team branch holds more code, it may just be unnecessary or even redundant.
In general, this is rarely fun. If you are asked to do it, try to convince your client of the first option since investing time into removing almost-finished features gives them no real value for their money. Still, if they want it, I hope this guide helps you keep your sanity.