Does which refer to the previous word or the previous sentence? Also does it refer to something else if there is a comma?
Ah, sorry. An example would be:
The statue and the doll, which traveled across a desert ...
The statue and the doll which traveled across a desert ...
The doll, which traveled across a desert ...
The statue which traveled across a desert ...
Sorry about the sentence making no sense at all.
Are all of these correct? If so, what is the difference?
(I'm not a teacher.)
They're all correct. The difference is the type of clause. The commas denote a non-restrictive clause, which describes the subject. When there is no comma, it is a restrictive clause, meaning that it defines the subject. The difference seems subtle, but it can completely change the meaning of a sentence. I'll demonstrate with an example other than those which you provided:
(a) The man who talks is a happy man.
(b) The man, who talks, is a happy man.
Sentence (a) means that only men who talk can be happy (defining). Sentence (b) is talking about a specific man who is happy (describing).
Is there still some confusion, or did that clear everything up?
1.
Relative pronouns that begin a restrictive clause are never set off by commas. Restrictive clauses add essential information about the antecedent (without them the meaning of the sentence would be changed).
Non-restrictive clauses are usually set off by commas.
So, where you have a comma, the information about travel across the desert is just some extra information that is not essential to the sentence.
2. Small note:
When talking about people and anthropomorphised objects we use "who". In your example since the doll and the statue are doing some traveling, they seem to be anthropomorphic objects... so "who".
3.
Relative clauses are often misplaced. They need to be placed so it's clear what the antecedent is and so there's no ambiguity. You can read about misplaced modifiers here.
Thank you! That's what I needed.
1 Which refers to the previous sentence
You have brought the bigger block, which I do not like
= I do not like your bringing the bigger block
2 Which refers to the preceding word
You have brought the bigger block which I do not like
= I do not like the bigger block
Probably a little academic but, according to Quirk, the comma does the job.