While using git, I checked out a specific revision in my master branch:
checkout <branch hash> .
I only did this to take a look at some previous files, I made no changes. I then attempted to reset my current state to my latest revision. Unfortunately I attempted several commands because I wasn't sure if it initially worked; the commands included:
checkout master .
checkout HEAD .
reset HEAD --hard
I wasn't sure if it worked at first because of certain behavior that indicated a previous file of the old revision was present.
I then realized that my modified and new files were indeed restored to the current revision, however files that I deleted between the old revision and the current revision are still in my local directory. Is this supposed to occur? I imagine that no one would generally want old, deleted files to be present after returning to the current revision, and yet this appears to be the case.
I was wondering if I did something wrong for this to occur or if there is another command I can use to remove these unwanted files of the temporarily checked out revision?
See: GIT: When checking out an alternative branch, I want to clear ignored files
I believe you're looking for the git clean
command. If you do a quick git clean -nd <path>
, it will list all the un-tracked / deleted files that will be deleted upon a real run of the command.
If you're sure that includes all the files you want to delete, perform a git clean -df <path>
.
Reference: http://gitready.com/beginner/2009/01/16/cleaning-up-untracked-files.html