Identify which layers you want to merge and select them from the layer window. To choose multiple layers at once, hold Ctrl and left click on the layer you want to be merged.
Right-clicking won't open the options menu we need as it does in Photoshop. With Illustrator, instead, click on the menu icon in the upper-right corner of the Layers window box.
Choose Merge Selected from the list. Any selected layers will be combined into one.
If you want to undo merge, you have to act fast. The more actions you take like drawing lines, moving layers, etc will add to the edit history of your document. You can only undo recently made changes.
User Ctrl + Z to undo the merge.