Answer by Ben for How do I discard unstaged changes in Git?
My favorite is git checkout -p That lets you selectively revert chunks. See also: git add -p
View ArticleAnswer by vivekporwal04 for How do I discard unstaged changes in Git?
cd path_to_project_folder # take you to your project folder/working directory git checkout . # removes all unstaged changes in working directory
View ArticleAnswer by Bijan for How do I discard unstaged changes in Git?
git checkout -f man git-checkout: -f, --force When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. When checking out paths...
View ArticleAnswer by bbarker for How do I discard unstaged changes in Git?
What follows is really only a solution if you are working with a fork of a repository where you regularly synchronize (e.g. pull request) with another repo. Short answer: delete fork and refork, but...
View ArticleAnswer by GlassGhost for How do I discard unstaged changes in Git?
This works even in directories that are; outside of normal git permissions. sudo chmod -R 664 ./* && git checkout -- . && git clean -dfx Happened to me recently
View ArticleAnswer by twicejr for How do I discard unstaged changes in Git?
When you want to transfer a stash to someone else: # add files git add . # diff all the changes to a file git diff --staged > ~/mijn-fix.diff # remove local changes git reset && git checkout...
View ArticleAnswer by Mariusz Nowak for How do I discard unstaged changes in Git?
It seems like the complete solution is: git clean -df git checkout -- . git clean removes all untracked files (warning: while it won't delete ignored files mentioned directly in .gitignore, it may...
View ArticleAnswer by blak3r for How do I discard unstaged changes in Git?
I really found this article helpful for explaining when to use what command: http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/ There are a couple different cases: If you haven't staged...
View ArticleAnswer by tjb for How do I discard unstaged changes in Git?
Another way to get rid of new files that is more specific than git clean -df (it will allow you to get rid of some files not necessarily all), is to add the new files to the index first, then stash,...
View ArticleAnswer by Elvis Ciotti for How do I discard unstaged changes in Git?
git clean -df Cleans the working tree by recursively removing files that are not under version control, starting from the current directory. -d: Remove untracked directories in addition to untracked...
View ArticleAnswer by artur for How do I discard unstaged changes in Git?
Tried all the solutions above but still couldn't get rid of new, unstaged files. Use git clean -f to remove those new files - with caution though! Note the force option.
View ArticleAnswer by Joshua Kunzmann for How do I discard unstaged changes in Git?
If you aren't interested in keeping the unstaged changes (especially if the staged changes are new files), I found this handy: git diff | git apply --reverse
View ArticleAnswer by CB Bailey for How do I discard unstaged changes in Git?
This checks out the current index for the current directory, throwing away all changes in files from the current directory downwards. git checkout . or this which checks out all files from the index,...
View ArticleAnswer by Greg Hewgill for How do I discard unstaged changes in Git?
Another quicker way is: git stash save --keep-index --include-untracked You don't need to include --include-untracked if you don't want to be thorough about it. After that, you can drop that stash with...
View ArticleAnswer by Tobi for How do I discard unstaged changes in Git?
For all unstaged files in current working directory use: git checkout -- . For a specific file use: git checkout -- path/to/file/to/revert -- here to remove argument ambiguation.
View ArticleHow do I discard unstaged changes in Git?
How do I discard changes in my working copy that are not in the index?
View ArticleAnswer by The Schwartz for How do I discard unstaged changes in Git?
Just as a reminder, newer versions of git has the restore command, which also is a suggestion when typing git status when you have changed files:(use "git add ..." to update what will be committed)(use...
View ArticleAnswer by Fairoz for How do I discard unstaged changes in Git?
If you want to restore unstaged files usegit restore --staged .
View ArticleAnswer by Mohamed Eldefrawy for How do I discard unstaged changes in Git?
To discard changes in working directory usegit checkout -- <file>-- means changes in current branchreferences:-https://www.baeldung.com/git-discard-unstaged-changes
View ArticleAnswer by Cary for How do I discard unstaged changes in Git?
To delete unstaged changes I tried "git restore ." as I was told by Git but it just didn't work. A very good way is to use:git revert --hardIt works perfectly. Its Git Help explains perfectly the...
View Article