Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to go back to last commit + delete all newly created files?

Tags:

git

As in the title: "How to go back to last commit + delete all newly created file?" Thanks.

like image 912
DevWL Avatar asked Sep 29 '13 10:09

DevWL


People also ask

How do I get my last commit back?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case.

How do I go back to a commit in history?

Go back to the selected commit on your local environmentUse git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .


1 Answers

If I understand the question correctly, you've done a bunch of work, haven't committed it, and want to git rid of that work and go back to your last commit. Is that correct? If so, I think you need a combination of two commands:

git reset --hard   # reverts tracked files to commit you were working from
git clean -f       # removes untracked files that haven't been added to git yet

Hope that helps.

like image 86
Mike Monkiewicz Avatar answered Nov 04 '22 22:11

Mike Monkiewicz