0

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?

  • 1
    You can get a specific version of a file usinf `git checkout `. – dan1st Jun 02 '21 at 13:33
  • thank you. and what should i do after this command. I want to restore all files to commit state and push,pull. – Jakub Troczyński Jun 02 '21 at 13:39
  • after checkout all files to commit i pushed, pulled on server: and i get: error: Your local changes to the following files would be overwritten by merge: error: The following untracked working tree files would be overwritten by merge: Aborting – Jakub Troczyński Jun 02 '21 at 13:49
  • Seems like you did not start this step on a clean repo. There is some more details to these steps here: https://stackoverflow.com/questions/67726323/git-how-to-filter-to-only-check-for-changes-on-a-single-file-from-recent-commi/67729141#67729141 – TheIceBear Jun 02 '21 at 14:17
  • Does this answer your question? [How do I revert a Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit) – Joe Jun 03 '21 at 10:07

1 Answers1

1

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

Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69