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.
Asked
Active
Viewed 806 times
-1

TheBAST
- 2,680
- 10
- 40
- 68
-
`restore` or `reset`? – TheBAST Nov 09 '19 at 03:16
-
`reset`, sorry: `git reset --hard
` should work – Serge Nov 09 '19 at 03:20
1 Answers
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
.
- Make a copy of the repo (on your drive), just in case.
git checkout master
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)git checkout chat-feature
- Check that this is what you want
master
to look like. git log -n 1
- Copy the commit id
git checkout master
git reset --hard <commit-id>
- Double check that things work and that's what you want.
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
-
-
-
it's like an environment configuration file, in laravel, usually it should be added in .gitignore – TheBAST Nov 09 '19 at 11:56