Search code examples
gitgit-reset

Git reset --hard, still got unwanted stuff from my pull


I accidentally pulled from another branch into my master. I wanted to revert those changes, so I made a:

git reset --hard HEAD^1

Now when I do git log, the latest commit is the correct (one step back) - but the files that the incorrect pull created are still left in my project. How come, and how can I get rid of them?

---Edit--- Nevermind, the files disappeared now. Maybe they were gone but my FTP-program cached them.


Solution

  • git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves unindexed files alone.

    The other PR which is referred here can contain newly indexed files which this branch is not aware of. So it might leave the files untracked.

    Use

    git clean -f -d
    

    to remove all the untracked files.