R
R
Romi2021-10-27 16:42:30
git
Romi, 2021-10-27 16:42:30

Is there an easy way to revert all changes in the working directory to the latest commit?

Let's say I made a commit "my last commit"

and after that I deleted two folders, three files in the working directory, and made changes to 10 files.

Can I revert my working directory back to the way it was when I made my last commit "my last commit"?

i googled. but in all the texts they start fooling their heads with some "three branches", something else, and by the fifth paragraph I don't understand anything at all :)

and I just need to roll back everything to the last state for which I made a commit - for that's what Git is made of (well, relatively speaking).

Let's say I didn't add changes to the index, I didn't do anything with the git at all, I just made changes to the structure of files and folders.

as?

upd.: while writing this, I thought: make another commit with changes, and then git checkout <hash of the previous commit>, and then delete the commit with changes - is this the easiest way? Or will there be changes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2021-10-27
@romicohen

Even two
git checkout .
or
git reset --hard

S
spaceatmoon, 2021-10-27
@spaceatmoon

There are even cooler ones, this is how I rolled back unsuccessful rebases.
We need 3 commands
git reflog allows you to view the history of repository operations.
get reset --hard "[email protected]{number}" with this command we can pull any state of the repository
git cherry-pick this command allows you to pull any commit by hash, be it from another branch, history

git cherry-pick "[email protected]{3}" - так мы вытащили наш запрятанный коммит

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question