-1

Just a dumb question from just a newb in git, Messed up alot with git, but now I was wondering if how can I restore to a previous version in the application, since my .env environment configuration file is now gone in my current master branch, I did merge my other branch with this one. I knew I made my latest work on my chat-feature branch, pretty much the 100% of the application was there, since the chat part and the payment feature of the application was there but when I checkout there, its not even working, I was wondering how can I go back to that previous commit that I made. When I git log I want to be back to this specific version.

enter image description here

TheBAST
  • 2,680
  • 10
  • 40
  • 68

1 Answers1

0

Restore + push --force

I don't like to recommend anything that requires --force but in your case it may be the cleanest solution. If you shared your code with others, don't follow this - you're changing history.

Let's make master be like chat-feature.

  1. Make a copy of the repo (on your drive), just in case.
  2. git checkout master
  3. git checkout -b master_copy (optional, but let's store what we currently have in master as a new branch; this will make it easy to use it if rewind too much)
  4. git checkout chat-feature
  5. Check that this is what you want master to look like.
  6. git log -n 1
  7. Copy the commit id
  8. git checkout master
  9. git reset --hard <commit-id>
  10. Double check that things work and that's what you want.
  11. git push --force
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • Thanks mate, but I think I wasn't paying attention to the right directory of the project, my project's on the `app-latest`, but I was on the `app-repo` directory, dang it, I'll getback to your answer once I'm done.. – TheBAST Nov 09 '19 at 06:37
  • I lost my `.env` file here.. What should I do now?? – TheBAST Nov 09 '19 at 07:43
  • I don't know what the `.env` file is :( – tymtam Nov 09 '19 at 07:51
  • it's like an environment configuration file, in laravel, usually it should be added in .gitignore – TheBAST Nov 09 '19 at 11:56