I read a book about 2001 or so it may have been an old book then even, I really have no idea. Details may be sketchy but I think in the intro a character 'dies' by rocks falling on top of him. Then he wakes up not remembering his previous life. You find out later that he is "reset" every now and then and is basically immortal, or close to it. He and the captain have this lifespan, and everyone else just lives and dies etc. their mission was to search out alien life. During the story they give up and head home and it ends with them arriving at earth to find the aliens have actually invaded. I think it may have been the second book to a trilogy but I never got to read the others. Been trying to remember the title or author for a long time!
The story is told through the narrative of Sparrow, a crew member aboard the Astron, which is a multigenerational starship sent from Earth on a search for life on other planets throughout the Milky Way. Sparrow fell off a cliff during one planetside excursion and is stricken with amnesia. No one will discuss his past with him and the computer has restricted his data, reasoning that he should "look within" to fully recover. Sparrow struggles to revive his memory and familiarizes himself with the Astron, the crew, the enigmatic Captain Kusaka, the state of the ship and its mission; in which the search for life has lasted over 2000 years with no success.
The ship has slowly shrunk from cannibalizing sealed off sections for parts and breaking apart from centuries of wear; meanwhile, the crew has dwindled from generations of selective breeding. The Captain wants to take the Astron to a section of the galaxy where stars are more numerous and older where planets are more likely to harbor life, but to do so they would have to cross the empty space between spiral arms they call "the Dark". Most members of the crew know that they will not survive the journey since it would take several centuries to cross and the ship would not make it with its current rate of attrition of their closed ecological system. But Captain Kusaka, who is immortal and obsessed with exploration, does not heed to the warnings and will do whatever it takes to complete the mission. As a result, the crew secretly try to plan a mutiny to seize control of the ship and return to Earth, the only place they know that harbors life.
Sparrow refuses to join the mutiny with his friends against Kusaka, but is torn since he knows they won't survive the trip and that chances of finding life are almost nonexistent, thus making the mission futile but the Captain won't accept it. Things change when Sparrow slowly discovers that he is also immortal like the Captain, and that he has lived previous "lives" on the ship as the same man but with different names and his memories of every previous identity are erased every generation by orders of the Captain. He learns that he originally volunteered for the role to be the mirror for every crew to "remember what its like to be human"; since they've been isolated from the rest of humanity over the centuries the crew has formed their own collective-mind culture that's overly benign and incapable of harm since they regard life as the most precious thing in existence (also makes them reluctant to mutiny). Sparrow also learns that he was the first mutineer and Kusaka erased his memories to keep the crew in line and Sparrow from seizing control of the ship since the Astron's central computer only responds to the minds of the immortal crew members, and should they be removed the ship would not function and would drift through space forever.
When they leave the last star system explored to enter "the Dark", Captain Kusaka tries to suppress the conspirators even though they are benign, but Sparrow gives them the resolution to fight when they learn that since the ship has traveled so far through relativistic time dilation, human civilization on Earth has ceased to exist and that they are the only known lifeforms left in the universe and that by venturing on would endanger them all, and since the governments that sent them out no longer exist also mean that Kusaka is no longer lawfully in command. Realizing that the crew has the will to turn against him, Kusaka decides to kill everyone and venture on alone by depressurizing the entire ship. Sparrow and his friends successfully get most of the crew onto shuttles and landers in time before life support fails and he fights Kusaka alone in the hidden bowels of the ship that hold the preserved remains of the original first generation crew, which trigger all of Sparrow's memories and past personalities to surface at once in a dissociative identity breakdown, which leads to the resurfacing of his original identity: Raymond Stone. In the ensuing fight Raymond fatally wounds Kusaka and before he dies he apologizes for everything he has done to the generations of crews for the sake of the mission and for what he did to him as friends when they left Earth.
With the mutiny over, Raymond takes command of the Astron and sets a course back to Earth, which takes 20 generations (400 years) to reach. During that time, Raymond watches the crew he has known age and die and recycled for mass on the ship as well as their descendant crews come and go, thus making him realize the value of life and the price of immortality.
The story ends when the Astron, after 2500 ship-years (or approximately 17,000 time-dilated Julian years as calculated earlier), finally returns to an uninhabited Earth for the descendants of the original crew and Raymond to repopulate. While they are celebrating, they are shocked to discover an alien ship has also found Earth.
As far as I know The Dark Beyond the Stars is a standalone novel. However, it may be based in part on Robinson's 1954 novella "The Oceans Are Wide" which features a generation ship called the Astro. "The Oceans Are Wide" was first published in Science Stories, April 1954, which is available at the Internet Archive (click here for download options).