The swap is not a sale
The key point is that a merger or demerger does not, by itself, tax you. Under Section 47, when you hand over shares of the amalgamating company and receive shares of the amalgamated company in a merger, that exchange is not regarded as a transfer, so no capital gain arises. The same applies in a demerger, where the resulting company issues you its shares: that issue is not a transfer either.
So there is nothing to pay and, usually, nothing to declare as a gain at the time of the reorganisation. The tax is not forgiven, it is postponed: the gain built into your original shares is preserved and will be taxed when you finally sell the new shares. The relief has conditions, chiefly that the amalgamated or resulting company is an Indian company and that you are given shares as consideration, but for an ordinary shareholder in a domestic merger or demerger those are met.
The cost and clock carry over
Because tax is deferred to the eventual sale, everything hinges on carrying the right cost and date across, and this is where people go wrong. In a merger, the new shares simply take the cost of your original shares under Section 49. In a demerger it is a split: your original cost is apportioned between the shares you keep in the demerged company and the new shares in the resulting company, in proportion to their values, so part of your old cost attaches to each.
Just as important, the holding period does not reset. Under Section 2(42A), the time you held the original shares is included in the holding period of the new shares, so a long-held investment stays long-term through the reorganisation and does not become short-term again. So when you sell the new shares, you compute the gain from your original cost, as carried or apportioned, and your original acquisition date. For an NRI this carryover is the same, and keeping the paperwork from the original purchase, through the merger or demerger, to the eventual sale is what makes the computation defensible. A practising CA carries the cost and date across correctly and computes the gain on the eventual sale.