Jakub Troczyński
Jakub Troczyński

Reputation: 11

How to restore previous files and changes

My workflow is: I make commits to branch main on local, I push changes. I have automated merge on github and pull on serwer.

I want to restore some files how it was in second commit after init. How to do this?

Upvotes: 0

Views: 55

Answers (1)

Wes Hardaker
Wes Hardaker

Reputation: 22262

The advantage of using version control systems like git is that it captures the entire history and you can always go back to the code in a particular snapshot. To do this:

  1. Find the code point in the history that you want to get the files from. Use git log and likely with --all to find the point in time with the sha identifier you want to get the files from. If the history is long, you might try git log --graph --decorate --all --oneline

  2. Then you can checkout that point in time using git checkout SHAID

  3. If you want to get back to this point in time frequently, you might add a tag at that point so you can get back easily: git tag MYTAG

  4. After doing whatever you want, go back to the main branch tip again using git checkout main

Upvotes: 1

Related Questions