Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (19.4k points)
Is there a way to go through different commits on a file. Say I modified a file 5 times and I want to go back to change 2 after I already committed and pushed to a repository.

In my understanding, the only way is to keep many branches, have I got that right? If I'm right I'm gonna have hundreds of branches in a few days, so I'm probably not understanding it really.

Could anyone clear that up, please?

1 Answer

0 votes
by (27.5k points)

Let us assume that the hash of the commit you want is XXXXXX:

$ git checkout XXXXXX -- file1/to/restore file2/to/restore

In order to revert to the commit before XXXXXX, append ~1:

git checkout XXXXXX~1 -- file1/to/restore file2/to/restore

Browse Categories