|You know it makes sense|
"Timeline! This is no time to argue about time. We don't have the time. What was I saying?"
—Counsellor Troi, First Contact
Time travel is a very useful plot device. Sometimes it is used in a loose way where the logic doesn't stand up to too much close examination, which is fine. But in many cases the logic of time travel is part of the fun, and it's worth teasing out the ideas.
In science fiction, including Star Trek, there are three main ideas about the way time works, for the purposes of time travel stories: the single timeline, the parallel universe, and diverging timelines.
(1) The single time-line
This is the most common. Travel in time means shuttling to and fro along the line of history. This idea has two subdivisions: a fixed time-line and a time-line that can be altered. In the fixed time-line, you may go to the past, but you were already there and everything you do is predetermined. A good example is Bill and Ted's Excellent Adventure: when Bill and Ted meet their earlier or later selves the scenes have to play out exactly the same each time. Interestingly, this doesn't cramp Bill and Ted's style. They make choices with apparent free will each time, it's just that they are located in a different "now" each time. This is essentially the traditional answer of how God's knowledge of the future can be reconciled with free will.
There's probably more scope for stories with the alternative idea that the time-line can be altered. This is the basis of a classic SF plot device where the heroes have to go and fix something in the past that has made the present go wrong. It happens repeatedly in Star Trek, for example in "The City on the Edge of Forever" (TOS), where Dr McCoy accidentally changes the past. Kirk and Spock have to go and change it back. It also happens in the film First Contact: the Borg go back to 21st century Earth and assimilate it. In "Yesterday's Enterprise" a ship comes from the past, and its disappearance leads to a war. So it has to go back. Normally the heroes still know the original reality, even though everyone else thinks the world is normal, because they're protected by the temporal field around the time machine, or because they're Guinan and have some strange super insight, or something. Don't argue, it's necessary.
Although the classic story involves changing things back, there are cases where this doesn't happen. There are lots of examples in written science fiction, such as Ray Bradbury's classic "A Sound of Thunder". It's not so common in Star Trek, partly because there is a strong belief that the timeline ought to be preserved (this is eventually named the Temporal Prime Directive). In "Timeless" (VOY) Kim and Chakotay come back to prevent the destruction of Voyager. They do so, and the story proceeds with the rescued Voyager. In "Endgame" (VOY), Captain (now Admiral) Janeway comes back, and not only brings the ship home faster but apparently destroys the Borg (though it may turn out they were only set back, if they are needed for a future series). No one suggests that they need to restore the timeline by bringing back the Borg. There's the Temporal Prime Directive, but on the other hand, let's not be hasty here.
A further complication is that, in Star Trek, there is a halfway house between the fixed timeline and the changeable timeline: the predestination paradox. (Temporal Investigations hate them.) You were already part of the events in the past, and the loop needs to be made for the timeline to continue; but it seems to be possible for it to be disrupted. "Assignment Earth" (TOS) is eventually revealed to have been a time loop, though this is not very significant. It's possible that "First Contact" involves a loop.
In predestination paradoxes, there is only one timeline. The events including the time travellers have always been there. It is possible that "First Contact" involves a predestination paradox, but it isn't clear—the issue arises in Star Trek Enterprise. In "Regeneration" (ENT) some Borg from the sphere are revived in the 22nd century, but of course no-one knows what they are. Captain Archer finds a record of Zefram Cochrane talking about the Borg. So, it seems there are two possibilities. The first is that the timeline "after" the events of First Contact is slightly changed from its original form: for example, there are now Borg bodies lying around. In the original 22nd century, Captain Archer never encountered any Borg, but Enterprise is showing us the history "after" the change. The second possibility is that it's a time loop: Cochrane's flight was always made with the Enterprise present, and the Borg were always in the 22nd century Arctic. There's some evidence in favour of this: at the end of "Regeneration" the Borg send a signal to the Delta Quadrant with Earth's location, and Archer speculates that they have just postponed the invasion till the 24th century. So, the Borg came in the 24th century because they got a message from Borg in the 22nd century, who were there because they came in the 24th century, because... However, if it's a time loop, we have the complication that there is definitely a timeline in First Contact where the Borg assimilated Earth—we even see it briefly before the Enterprise follows the Borg back to the 21st century. You can see why Temporal Investigations hate those predestination paradoxes.
Star Trek mainly sticks to the single time line and the parallel Mirror Universe. The single time line can definitely be changed; there are no examples of a Bill and Ted fixed timeline. At this point we have to mention the Kelvin Timeline, which is the reality in which the Abrams films take place. The arrival of Nero from the future is supposed to produce an alternate history which is separate from the one we are familiar with from the TV series. This introduces yet another variation: intervention from the future produces a new history, which however does not replace the previous one (as in "The City on the Edge of Forever" or "Timeless") but exists separately. This concept serves the purpose of allowing the Abrams films to have a new history without implying that the rest of Star Trek never happened. However it is not of much use for time travel stories in general, because it would mean that when you go back to change history, you can't: the world you left behind doesn't change as a result.
(2) The parallel universe
The parallel universe exists separately from ours. You can cross over into it due to some technical anomaly, but what happens there doesn't affect us. In Star Trek this is the basis of the Mirror Universe, though the Mirror Universe also has the special characteristics we all know and love.
(3) Diverging worlds
The universe splits into different possible worlds according to what happens. This is, in fact, quite respectable scientifically—it's the Many Worlds Interpretation of quantum mechanics. Everything that can happen, does happen. This was the basis of the classic Star Trek episode "Parallels" (TNG), where Worf somehow gets unfastened from his original universe and starts drifting between realities. Star Trek didn't pursue this later.
Note on language and "meta-time": When we discuss time travel, there's a problem with language. We might say, "Originally, Zefram Cochrane flew his warp ship on 5th April 2063 and the Vulcans arrived. But now, the Borg damaged his ship, so he couldn't fly, and First Contact didn't happen." If you think about it, we're telling a story with events in order: first, Cochrane does this, then, the Borg stop him... But there isn't really any past, present and future here. Cochrane flew on 5th April, the Borg damage his ship on 4th April, and on 5th April he didn't fly.
What this means is that for this sort of story we have to imagine a sort of meta-time: a before and after, not of dates within a timeline, but of changes between timelines. Cochrane's flight is "before" the Borg stop him, and then "after" that Picard comes and defeats the Borg so that Cochrane does fly. This seems to be approximately the concept called "physiotime" in Isaac Asimov's great time-travel novel The End of Eternity.
Note on Back to the Future:
The film Back to the Future is a good example of the looser sort of time-travel story—its logic isn't intended to bear too heavy a load. However, it illustrates several time-line issues. The concept is essentially a changeable single timeline. Marty's arrival in the past compromises his own existence, but he is able to undo the damage; however, he does not restore the exact previous situation (notably, his parents' relationship has altered). The changes all seem to be positive so there isn't any incentive to change them back. They do raise some interesting questions, though. Marty sees himself disappearing into the past, as he remembers. But that Marty is a Marty who grew up with the happier and more successful parents. Will he understand the situation in 1955, and even if he does, will he deal with it in the same way? Perhaps his father confided in him how he only got his act together with the help of a guy he knew briefly in high school. There does seem to be some meta-time concept: a "before" version with the less successful parents and the Twin Pines Mall, and a "later" version with the successful parents and the Lone Pine Mall. It seems, though this is not explicit, that Doc really was killed in the "earlier" version.
There is also an apparent predestination paradox, in which by playing "Johnny B. Goode", which he learnt of course from Chuck Berry, Marty accidentally inspires Chuck Berry to write it in the first place. In this sort of paradox there is the question of where the song came from—this has been discussed a lot in other stories, including Harry Harrison's Technicolor Time Machine. However, the predestination paradox implies that there "was never" a version in which Marty was absent. This however is reaching the point where we are asking too much. Back to the Future includes time-travel paradoxes that you are meant to think about and enjoy, but also logical problems that you probably aren't supposed to worry about. Mind you, it can be a lot of fun trying to make sense of them, if you like this sort of thing.
Back to the Future 3 includes what may possibly be a loose end in the script. In an "earlier" version, Clara had died in an accident, but Doc rescued her. Star Trek fans will immediately think of Edith Keeler ("The City on the Edge of Forever", TOS), but nothing is made of this. At the end of the film Doc stays in the nineteenth century with her. I wonder if in some version of the script she was going to come back with him to 1985, on the basis that she no longer belongs in her own time?
 In Austin Powers: The Spy Who Shagged Me, Austin (about to set off into the past) starts worrying about the logical implications, and then says, "Oh no, I've gone cross eyed." His boss, Basil Exposition, replies "I suggest you don't worry about those things and just enjoy yourself!" and then turns to the audience and says "That goes for you all too." [Return]