An answer to this question could be very long and complicated unless we focus on a specific scenario. So in an attempt to keep this (relatively) concise, I'm going to focus on the scenario I think you cited in the question.
In the episode you mentioned, "Yesterday's Enterprise," the timeline was altered when the Enterprise-C passed through a temporal rift from the year 2344 to the year 2366. The Enterprise-C eventually returned through the temporal rift to the year 2344, which altered the timeline again, back to something broadly resembling the previous one. However, a version of Tasha Yar who was native to the alternate 2366 was on board the Enterprise-C when it returned to 2344.
The ultimate fate of that version of Tasha was never shown on-screen, but in a later episode, "Redemption," we were introduced to Sela, a Romulan commander who bore a striking resemblance to her. In the following episode, "Redemption II," Sela told Picard that she was Tasha's daughter, and that Tasha had been captured by the Romulans, made the consort of a Romulan general, and later executed, after being sent back in time by Picard himself.
PICARD: All right. Why did I invite you here?
SELA: You want the answer to the only question on your mind. How could Tasha Yar be my mother?
PICARD: It's been suggested that she was aboard the Enterprise C when it was destroyed twenty four years ago, that she was one of the survivors and that obviously you are a product of a union between her and a Romulan.
SELA: But you know that's impossible. She would have been a child when that battle occurred.
PICARD: And yet you claim that it is possible, that you're the daughter of Tasha Yar.
SELA: Yes, she was on that ship twenty four years ago. She was sent there by you from the future. She was among those few who survived. They were all to have been executed after the interrogation, but a Romulan general saw her and became enamoured with her. So a deal was struck. Their lives would be spared if she became his consort. I was born a year later.
PICARD: I want to meet your mother. Can you arrange that?
SELA: One night, when I was four years old, she came to me. She bundled me up and she told me to stay quiet as we left the compound. I realised she was taking me away. She was taking me away from my home, my father, so I cried out. My father offered her life. He gave her a home, gave her a child, and how did she repay him? By betrayal. They executed her. Everything in me that was human died that day with my mother. All that's left is Romulan. Never doubt that.
PICARD: Doubts? I'm full of them. But nothing in my experience can persuade me that what you have told me is true. And I do know one thing. It will not affect my judgment at our next encounter.
Star Trek: The Next Generation - S05E01 - "Redemption II"
Picard was extremely sceptical regarding Sela's claims, which makes sense, since she was an enemy of the Federation, and he had no recollection of ever having sent Tasha back in time (it was his counterpart from the alternate 2366 who did that). However, Guinan corroborated Sela's story, and she is a reliable source, since she was on board the Enterprise-D in "Yesterday's Enterprise" and somehow retained an awareness of both timelines despite the changes.
GUINAN: Am I intruding?
PICARD: No, not at all. Is something wrong?
GUINAN: News travels fast. I heard that Tasha Yar's daughter is aboard the Romulan ship.
PICARD: I think that the Romulans are just hoping to create a distraction. They want to keep us off balance.
GUINAN: How much do you know about what happened to the last ship called Enterprise?
PICARD: Enterprise C? She was lost at the battle of Narendra Three, defending a Klingon outpost from the Romulans.
GUINAN: And the survivors?
PICARD: There were stories of prisoners taken back to Romulus, but these were only rumours.
GUINAN: No. There were survivors. And Tasha Yar was one of them.
PICARD: Guinan, that was twenty three years ago. Tasha Yar was only a child.
GUINAN: I know that. But I also know she was aboard that ship and she was not a child. And I think you sent her there.
PICARD: How can that be?
GUINAN: I don't know. I just know that you did.
PICARD: Tasha died, a year before you came on the Enterprise. You never met her.
GUINAN: I know that.
PICARD: If you have only a vague intuition
GUINAN: You can't just dismiss this. If I'm right, then you are responsible for this whole situation.
PICARD: I think that it's time I met Commander Sela.
Star Trek: The Next Generation - S05E01 - "Redemption II"
If Sela was telling the truth -- and judging by what Guinan had to say, it appears she was, at least for the most part -- it suggests that the alternate version of Tasha must have retained at least some of her memory of the alternate 2366 after arriving in 2344, otherwise how would Sela have known that Picard specifically sent her there? The simplest explanation is that Tasha retained this memory and passed that information on to her daughter.
We can't be sure that Tasha retained her full memory of the alternate 2366 -- to the extent that any normal human fully remembers their past -- however, I'd guess that she probably did. When the Enterprise-C returned to 2344, the timeline was altered in such a way that the Enterprise-D she left behind in the year 2366 physically ceased to exist and was replaced by a similar-but-different version of the ship with a similar-but-different crew.
If Tasha were subject to these changes as well, she should've physically ceased to exist herself, like Marty McFly fading from existence in Back to the Future. And unlike Enterprise-D crew remaining in the year 2366, she wouldn't have been replaced by another version of herself with alternate memories -- at least not in that time period (2344) -- because she never lived to that age in the other timeline; her alternate self died when she was two years younger.
The fact that Tasha didn't cease to exist when everything else from her native timeline was erased and replaced suggests that Back to the Future rules don't apply here, and that these episodes conform to a version of time-travel more closely resembling that of the Terminator franchise, in which both cyborgs sent back in time from the future, and a child fathered by a man from the future, continue to exist and retain their original memories even when the future is fundamentally altered.