Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...