gitrevertvcs-checkout

How do I revert Git changes that I haven't committed?


I'm using git on Mac OS X. How do I revert changes to a file? The changes aren't committed yet. I tried

localhost:myproject davea$ git checkout -- .gitignore
error: pathspec '.gitignore' did not match any file(s) known to git.

The above error doesn't make sense because when I try and pull from the remote repository, it complains taht I have the file it can't overwrite ...

localhost:myproject davea$ git pull origin master
Username for 'https://github.com': myuser
Password for 'https://myuser@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/JBSinc/myproject.git/'
localhost:myproject davea$ git pull origin master
Username for 'https://github.com': myuser
Password for 'https://myuser@github.com': 
From https://github.com/JBSinc/myproject
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
    .gitignore
Please move or remove them before you can merge.
Aborting

Solution

  • '.gitignore' is the one file that prevents your git commands from affecting whatever files or directories defined in it. if it's not useful to you, you may remove it with rm as suggested above. your git commands will not affect it. also, in other cases when you have untracked files you would like to get rid of, you can always use:

    git clean --force
    

    this will silently remove anything not committed and your directory will be clean.