This question already has an answer here:
How can I clear my working directory in git?
This question already has an answer here: How can I clear my working directory in git? |
|||
marked as duplicate by Marc Audet, Jake N, giammin, J. Costa, Emile Feb 18 '14 at 11:59This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
|||
|
To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file):
This is mentioned in the
To reset the entire repository to the last committed state:
To remove untracked files, I usually just delete all files in the working copy (but not the A better way is to use
will remove untracked files, including directories ( Relevant links:
|
|||||||||||||||||||||
|
Edit:
It's not well advertised but
|
|||||||||||||||||||||
|
All the answers so far retain local commits. If you're really serious, you can discard all local commits and all local edits by doing:
For example:
This makes your local repository exactly match the state of the origin (other than untracked files). If you accidentally did this after just reading the command, and not what it does :), use git reflog to find your old commits. |
||||
|
You could create a commit which contains an empty working copy. This is a generally safe, non-destructive approach because it does not involve the use of any brute-force reset mechanisms. First you hide all managed content with
Your working copy should now be clear of any managed content. All that remains are unmanaged files and the To re-populate your working copy...
|
|||||||||||||||||||||
|
To switch to another branch, discarding all uncommitted changes (e.g. resulting from Git's strange handling of line endings):
I had a working copy with hundreds of changed files (but empty |
|||
|
To reset a specific file as git status suggests:
To reset a folder
|
|||
|