Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
3 views
in DevOps and Agile by (29.3k points)
edited by

I'm trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I respond with head is now at 18c3773... but when I look at my local source all the files are still there. What am I missing?

2 Answers

0 votes
by (50.2k points)

To  unstage all files that you might have staged with git add using:

git reset

To revert all local uncommitted changes (should be executed in repo root):

git checkout .

You can also revert uncommitted changes only to a particular file or directory:

git checkout [some_dir|file.txt]

Yet another way to revert all uncommitted changes 

git reset --hard HEAD

This will remove all local untracked files, so the only git tracked files will remain for that use:

 git clean -fdx

WARNING: -x will also remove all ignored files, including ones specified by .gitignore! You may want to use -n for the preview of files to be deleted.

Reference: https://git-scm.com/docs/git-clean#Documentation/git-clean.txt--X

+3 votes
by (27.5k points)

I would suggest you try these steps: 

$ git add . (adding everything) 

$ git stash 

$ git stash drop

You can also try this simple one liner: 

$ git add . && git stash && git stash drop

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...