Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

When I run git reset --hard HEAD, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a git status shows a big list of untracked files.

How do you tell git "Just bring it back to EXACTLY what was in the last pull, nothing more, nothing less"?

1 Answer

0 votes
by (27.5k points)

First, you have to use git clean -f -d to get rid of untracked files and directories in your working copy.

If you need to reset the whole repository to master including all git submodules, run this script:

git reset --hard HEAD

git clean -f -d

git checkout master

git fetch origin master

git reset --hard origin/master

git pull

git submodule update

git submodule update --init --recursive

git submodule foreach git reset --hard HEAD

git submodule foreach git clean -f -d

git submodule foreach git submodule update --init --recursive

git submodule foreach git fetch

git submodule foreach git pull

git status

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...