What does it mean when a confirmed transaction gets reversed? I am using bitcoin-cli to do verification of transfer. From the wiki, it mentions that a transaction has a higher confidence in confirmation after 6 blocks deep. However, a block that is put into the blockchain should not to be reverted or removed. 

So I want to know what will trigger a confirmed transaction to become invalid and what will actually happen to the blocks and the blockchain?

Especially in bitcoin-cli when I get a block with the target transaction, what will happen if this transaction does not get the final confirmation?

Reference: https://en.bitcoin.it/wiki/Confirmation
Every now and then, blocks become orphaned during what is called blockchain reorganization.  This happens when two valid blocks are found at about the same time, and the network is split on which one is considered the top of the blockchain.  These two blocks can contain different sets of transactions, so one block may contain your transaction while the other one doesn't.

This situation will be automatically resolved.  Let's call the two blocks A and B.  Eventually, a new block will be found on top of one of the two competing blocks.  Let's say this new block, C, is found on top of A.  When C is broadcast, any nodes recognizing the B as the tip of the chain will see that more work as been done on the other fork, and will orphan B in favor of A and C.  It will be like B never happened.  If your transaction was confirmed as part of B, it will be like your transaction never happened.

The good news is that it is likely that A and B share a good deal of the same transactions.  Even though you may have been recognizing B instead of A, there's a good chance the transaction will be already confirmed in A when you come around to recognizing it.  If not, it means the transaction will still be in the mempool, and is likely included in C or will be included in a later block.

As you can see, the odds of this happening go down as each new block piles on top of the block containing your transaction.  By the time 5 blocks have been mined on top of the block containing your transaction (thus 6 confirmations) there is no reasonable chance of that block being orphaned.  The transaction is now permanent.