Most people probably don’t even think about the difference between that and which. However, they are used for different purposes, and they affect comma usage.
The word that is used to introduce something called a restrictive clause. This is a fancy term for a group of words that limits (or makes more specific) the noun in front of it.
Example: The tea that I am brewing has a strong cinnamon scent. (The clause that I am brewing limits the noun tea. I’m only talking about the tea that I am brewing. I’m not talking about all the different teas in the world.)
The word which is used to introduce nonrestrictive clauses. These do not limit or specify the noun in front of them.
Example: We bought some tea, which happens to be my favorite drink, as well as some scones. (The clause which happens to be my favorite drink does not limit or specify what kind of tea I’m talking about.)
A Word About Punctuation
Notice that the restrictive clauses, which all begin with that, do not need commas around them. They are considered necessary to the meaning of the sentence. If you took out a restrictive clause, your sentence would change meaning.
Nonrestrictive clauses, which start with which, do need commas around them. The clauses are considered “unnecessary” because you could remove them without altering the basic meaning of the sentence. Since they are “throwaway” clauses, we tend to pause when we say them. Almost as if they are asides; hence, the commas on either side of them.