0

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?

Zoe
  • 27,060
  • 21
  • 118
  • 148
user1167662
  • 1,245
  • 3
  • 16
  • 25
  • Your problem was the `.` path at the end of your checkout: you told it to check out that path, `.`, i.e. recursively the entire current directory, from that commit, without switching commits. So it added the entire `master` checkout to your worktree and index. – jthill Jul 14 '15 at 18:05

1 Answers1

1

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

Community
  • 1
  • 1
Brainless Box
  • 587
  • 9
  • 16
  • 1
    awesome, and thanks for the link! I understand why the behavior I observed is the default now too. Just something to note, the -f flag is also required for the actual delete command, or else I receive: "fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean". so `git clean -df ` did precisely the trick! – user1167662 Jul 24 '13 at 03:23
  • 1
    @user1167662 Thanks; I updated the answer so anyone else looking into this will see it. – Brainless Box Jul 24 '13 at 13:52