There are several ways. One is geology – which is the science comprising the study of solid Earth, the rocks of which it is composed, and the processes by which it evolves. Geology gives insight into the history of the Earth, as it provides the primary evidence for plate tectonics, the evolutionary history of life, and past climates.
Another is Palaeontology – which is the study of prehistoric life. It includes the study of fossils to determine organisms’ evolution and interactions with each other and their environments.
Yet another is Archeology – which is is the study of human society, primarily through the recovery and analysis of the material culture and environmental data that they have left behind, which includes artifacts, architecture, biofacts and cultural landscapes.
There are many other methods too, and the knowledge collected from all of these fields are used to generate an accurate picture of the history of the earth.
Well, we have the fossil record that can tell us a lot about the different organisms that lived at various times – this goes back about 3.5 billion years. We can also date various findings by carrying out radiocarbon dating which is based on the half-life carbon14 (up to about 65000 years back). We can also examine biological molecules and then make assumptions about the characteristics of organisms. And, we can look at the DNA of various organisms and make assumptions on their evolution according to gene similarity.
Going further back, we start to rely more and more on theory.