<p>How do I discard changes in my working copy that are not in the index?</p>

[{'answer_id': 52713, 'author': 'Tobi', 'author_id': 5422, 'author_profile': 'https://Stackoverflow.com/users/5422', 'pm_score': 13, 'selected': False, 'text': '<p>For all <em>unstaged</em> files in current working directory use:</p>\n<pre><code>git restore .\n</code></pre>\n<p>For a specific file use:</p>\n<pre><code>git restore path/to/file/to/revert\n</code></pre>\n<p>That together with <code>git switch</code> replaces the overloaded <code>git checkout</code> (<a href="https://stackoverflow.com/questions/58003030/what-is-the-git-restore-command-and-what-is-the-difference-between-git-restor">see here</a>), and thus removes the argument disambiguation.</p>\n<p>If a file has both staged and unstaged changes, only the unstaged changes shown in <code>git diff</code> are reverted. Changes shown in <code>git diff --staged</code> stay intact.</p>\n<p><strong>Before Git 2.23</strong></p>\n<p>For all unstaged files in current working directory:</p>\n<pre><code>git checkout -- .\n</code></pre>\n<p>For a specific file:</p>\n<pre><code>git checkout -- path/to/file/to/revert\n</code></pre>\n<p><code>--</code> here to remove ambiguity (this is known as  <a href="https://git-scm.com/docs/git-checkout#_argument_disambiguation" rel="noreferrer">argument disambiguation</a>).</p>\n'}, {'answer_id': 52719, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 13, 'selected': True, 'text': "<p>Another quicker way is:</p>\n\n<pre><code>git stash save --keep-index --include-untracked\n</code></pre>\n\n<p>You don't need to include <code>--include-untracked</code> if you don't want to be thorough about it.</p>\n\n<p>After that, you can drop that stash with a <code>git stash drop</code> command if you like.</p>\n"}, {'answer_id': 1021384, 'author': 'CB Bailey', 'author_id': 19563, 'author_profile': 'https://Stackoverflow.com/users/19563', 'pm_score': 9, 'selected': False, 'text': '<p>This checks out the current index for the current directory, throwing away all changes in files from the current directory downwards.</p>\n\n<pre><code>git checkout .\n</code></pre>\n\n<p>or this which checks out all files from the index, overwriting working tree files.</p>\n\n<pre><code>git checkout-index -a -f\n</code></pre>\n'}, {'answer_id': 6854469, 'author': 'Joshua Kunzmann', 'author_id': 121037, 'author_profile': 'https://Stackoverflow.com/users/121037', 'pm_score': 6, 'selected': False, 'text': "<p>If you aren't interested in keeping the unstaged changes (especially if the staged changes are new files), I found this handy:</p>\n\n<pre><code>git diff | git apply --reverse\n</code></pre>\n"}, {'answer_id': 7773568, 'author': 'artur', 'author_id': 201852, 'author_profile': 'https://Stackoverflow.com/users/201852', 'pm_score': 5, 'selected': False, 'text': "<p>Tried all the solutions above but still couldn't get rid of new, unstaged files.</p>\n\n<p>Use <code>git clean -f</code> to remove those new files - <em>with caution though!</em> Note the force option.</p>\n"}, {'answer_id': 8415829, 'author': 'E Ciotti', 'author_id': 415032, 'author_profile': 'https://Stackoverflow.com/users/415032', 'pm_score': 8, 'selected': False, 'text': '<pre><code>git clean -df\n</code></pre>\n\n<p>Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.</p>\n\n<p><code>-d</code>: Remove untracked directories in addition to untracked files</p>\n\n<p><code>-f</code>: Force (might be not necessary depending on  <code>clean.requireForce</code> setting)</p>\n\n<p>Run <code>git help clean</code> to see the manual</p>\n'}, {'answer_id': 11047504, 'author': 'tjb', 'author_id': 530634, 'author_profile': 'https://Stackoverflow.com/users/530634', 'pm_score': 3, 'selected': False, 'text': "<p>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, then drop the stash.</p>\n\n<p>This technique is useful when, for some reason, you can't easily delete all of the untracked files by some ordinary mechanism (like rm).</p>\n"}, {'answer_id': 11942626, 'author': 'blak3r', 'author_id': 67268, 'author_profile': 'https://Stackoverflow.com/users/67268', 'pm_score': 6, 'selected': False, 'text': '<p>I really found this article helpful for explaining when to use what command: <a href="http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/" rel="noreferrer">http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/</a></p>\n\n<p>There are a couple different cases:</p>\n\n<ol>\n<li><p>If you haven\'t staged the file, then you use <code>git checkout</code>.  Checkout "updates files in the working tree to match the version in the index".  If the files have not been staged (aka added to the index)... this command will essentially revert the files to what your last commit was.  </p>\n\n<p><code>git checkout -- foo.txt</code></p></li>\n<li><p>If you have staged the file, then use git reset.  Reset changes the index to match a commit.</p>\n\n<p><code>git reset -- foo.txt</code> </p></li>\n</ol>\n\n<p>I suspect that using <code>git stash</code> is a popular choice since it\'s a little less dangerous.  You can always go back to it if you accidently blow too much away when using git reset.  Reset is recursive by default.</p>\n\n<p>Take a look at the article above for further advice.</p>\n'}, {'answer_id': 12184274, 'author': 'Mariusz Nowak', 'author_id': 96806, 'author_profile': 'https://Stackoverflow.com/users/96806', 'pm_score': 11, 'selected': False, 'text': '<p>It seems like the complete solution is:</p>\n<pre><code>git clean -df\ngit checkout -- .\n</code></pre>\n<p><strong>WARNING</strong>: while it won\'t delete ignored files mentioned directly in .gitignore, <code>git clean -df</code> <strong>may delete ignored files residing in folders</strong>.</p>\n<p><a href="https://git-scm.com/docs/git-clean" rel="noreferrer"><code>git clean</code></a> removes all untracked files and <code>git checkout</code> clears all unstaged changes.</p>\n'}, {'answer_id': 17530055, 'author': 'twicejr', 'author_id': 449217, 'author_profile': 'https://Stackoverflow.com/users/449217', 'pm_score': 3, 'selected': False, 'text': '<p>When you want to transfer a stash to someone else:</p>\n\n<pre><code># add files\ngit add .  \n# diff all the changes to a file\ngit diff --staged &gt; ~/mijn-fix.diff\n# remove local changes \ngit reset &amp;&amp; git checkout .\n# (later you can re-apply the diff:)\ngit apply ~/mijn-fix.diff\n</code></pre>\n\n<p>[edit] as commented, it ís possible to name stashes. Well, use this if you want to share your stash ;)</p>\n'}, {'answer_id': 18632808, 'author': 'GlassGhost', 'author_id': 144020, 'author_profile': 'https://Stackoverflow.com/users/144020', 'pm_score': 4, 'selected': False, 'text': '<p>This works even in directories that are; outside of normal git permissions.</p>\n\n<pre><code>sudo chmod -R 664 ./* &amp;&amp; git checkout -- . &amp;&amp; git clean -dfx\n</code></pre>\n\n<p>Happened to me recently</p>\n'}, {'answer_id': 20930217, 'author': 'bbarker', 'author_id': 3096687, 'author_profile': 'https://Stackoverflow.com/users/3096687', 'pm_score': 3, 'selected': False, 'text': '<p>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 <strong>read the warnings on github</strong>.</p>\n\n<p>I had a similar problem, perhaps not identical, and I\'m sad to say my solution is not ideal, but it is ultimately effective.</p>\n\n<p>I would often have git status messages like this (involving at least 2/4 files):</p>\n\n<pre><code>$ git status\n# Not currently on any branch.\n# Changes to be committed:\n#   (use "git reset HEAD &lt;file&gt;..." to unstage)\n#\n#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2var.dats\n#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2var.dats\n#\n# Changes not staged for commit:\n#   (use "git add &lt;file&gt;..." to update what will be committed)\n#   (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)\n#\n#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2Var.dats\n#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2Var.dats\n</code></pre>\n\n<p>A keen eye will note that these files have dopplegangers that are a single letter in case off. Somehow, and I have no idea what led me down this path to start with (as I was not working with these files myself from the upstream repo), I had switched these files. Try the many solutions listed on this page (and other pages) did not seem to help. </p>\n\n<p><strong>I was able to fix the problem by deleting my forked repository and all local repositories, and reforking. This alone was not enough; upstream had to rename the files in question to new filenames.</strong> As long as you don\'t have any uncommited work, no wikis, and no issues that diverge from the upstream repository, you should be just fine. Upstream may not be very happy with you, to say the least. As for my problem, it is undoubtedly a user error as I\'m not that proficient with git, but the fact that it is far from easy to fix points to an issue with git as well. </p>\n'}, {'answer_id': 23707009, 'author': 'Bijan', 'author_id': 323720, 'author_profile': 'https://Stackoverflow.com/users/323720', 'pm_score': 5, 'selected': False, 'text': '<p><code>git checkout -f</code></p>\n\n<hr>\n\n<p><code>man git-checkout</code>:</p>\n\n<p><code>-f, --force</code></p>\n\n<p>When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.</p>\n\n<p>When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.</p>\n'}, {'answer_id': 23951175, 'author': 'vivekporwal04', 'author_id': 1856106, 'author_profile': 'https://Stackoverflow.com/users/1856106', 'pm_score': 4, 'selected': False, 'text': '<pre><code>cd path_to_project_folder  # take you to your project folder/working directory \ngit checkout .             # removes all unstaged changes in working directory\n</code></pre>\n'}, {'answer_id': 26299506, 'author': 'Ben', 'author_id': 874660, 'author_profile': 'https://Stackoverflow.com/users/874660', 'pm_score': 7, 'selected': False, 'text': '<p>My favorite is</p>\n\n<pre><code>git checkout -p\n</code></pre>\n\n<p>That lets you selectively revert chunks.</p>\n\n<p>See also:</p>\n\n<pre><code>git add -p\n</code></pre>\n'}, {'answer_id': 29170402, 'author': 'Ivan', 'author_id': 3070485, 'author_profile': 'https://Stackoverflow.com/users/3070485', 'pm_score': 3, 'selected': False, 'text': '<p>If all the staged files were actually committed, then the branch can simply be reset e.g. from your GUI with about three mouse clicks: <strong>Branch</strong>, <strong>Reset</strong>, <strong>Yes</strong>!</p>\n\n<p>So what I often do in practice to revert unwanted local changes is to commit all the good stuff, and then reset the branch.</p>\n\n<p>If the good stuff is committed in a single commit, then you can use "amend last commit" to bring it back to being staged or unstaged if you\'d ultimately  like to commit it a little differently.</p>\n\n<p>This might not be the technical solution you are looking for to your problem, but I find it a very practical solution. It allows you to discard unstaged changes selectively, resetting the changes you don\'t like and keeping the ones you do.</p>\n\n<p>So in summary, I simply do <strong>commit</strong>, <strong>branch reset</strong>, and <strong>amend last commit</strong>.</p>\n'}, {'answer_id': 29847393, 'author': 'piyushmandovra', 'author_id': 3568378, 'author_profile': 'https://Stackoverflow.com/users/3568378', 'pm_score': 5, 'selected': False, 'text': '<p>simply say</p>\n\n<pre><code>git stash\n</code></pre>\n\n<p>It will remove all your local changes. You also can use later by saying</p>\n\n<pre><code>git stash apply \n</code></pre>\n\n<p>or \n    git stash pop</p>\n'}, {'answer_id': 31886761, 'author': 'Nick', 'author_id': 1563884, 'author_profile': 'https://Stackoverflow.com/users/1563884', 'pm_score': 5, 'selected': False, 'text': "<p>Instead of discarding changes, I reset my remote to the origin. Note - this method is to completely restore your folder to that of the repo. </p>\n\n<p>So I do this to make sure they don't sit there when I git reset (later - excludes gitignores on the Origin/branchname)</p>\n\n<p>NOTE: If you want to keep files not yet tracked, but not in GITIGNORE you may wish to skip this step, as it will Wipe these untracked files not found on your remote repository (thanks @XtrmJosh).</p>\n\n<pre><code>git add --all\n</code></pre>\n\n<p>Then I </p>\n\n<pre><code>git fetch --all\n</code></pre>\n\n<p>Then I reset to origin</p>\n\n<pre><code>git reset --hard origin/branchname\n</code></pre>\n\n<p>That will put it back to square one. Just like RE-Cloning the branch, WHILE keeping all my gitignored files locally and in place.</p>\n\n<p>Updated per user comment below:\nVariation to reset the to whatever current branch the user is on. </p>\n\n<pre><code>git reset --hard @{u}\n</code></pre>\n"}, {'answer_id': 32523024, 'author': 'Asped', 'author_id': 1132243, 'author_profile': 'https://Stackoverflow.com/users/1132243', 'pm_score': 5, 'selected': False, 'text': "<p>You can use git stash - if something goes wrong, you can still revert from the stash.\nSimilar to some other answer here, but this one also removes all unstaged files and also all unstaged deletes:</p>\n\n<pre><code>git add .\ngit stash\n</code></pre>\n\n<p>if you check that everything is OK, throw the stash away:</p>\n\n<pre><code>git stash drop\n</code></pre>\n\n<p>The answer from Bilal Maqsood with <code>git clean</code> also worked for me, but with the stash I have more control - if I do sth accidentally, I can still get my changes back</p>\n\n<p><strong>UPDATE</strong></p>\n\n<p>I think there is 1 more change (don't know why this worked for me before):</p>\n\n<p><code>git add . -A</code> instead of <code>git add .</code></p>\n\n<p>without the <code>-A</code> the removed files will not be staged</p>\n"}, {'answer_id': 32897226, 'author': 'onalbi', 'author_id': 3090602, 'author_profile': 'https://Stackoverflow.com/users/3090602', 'pm_score': 3, 'selected': False, 'text': '<p>If you are in case of submodule and no other solutions work try:</p>\n\n<ul>\n<li><p>To check what is the problem (maybe a "dirty" case) use:</p>\n\n<p><code>git diff</code></p></li>\n<li><p>To remove stash</p>\n\n<p><code>git submodule update</code></p></li>\n</ul>\n'}, {'answer_id': 33863756, 'author': 'Malcolm Boekhoff', 'author_id': 1388639, 'author_profile': 'https://Stackoverflow.com/users/1388639', 'pm_score': 3, 'selected': False, 'text': '<p>None of the solutions work if you just changed the <em>permissions</em> of a file (this is on DOS/Windoze)</p>\n\n<pre>\nMon 23/11/2015-15:16:34.80 C:\\...\\work\\checkout\\slf4j+> git status\nOn branch SLF4J_1.5.3\nChanges not staged for commit:\n  (use "git add ..." to update what will be committed)\n  (use "git checkout -- ..." to discard changes in working directory)\n\n        modified:   .gitignore\n        modified:   LICENSE.txt\n        modified:   TODO.txt\n        modified:   codeStyle.xml\n        modified:   pom.xml\n        modified:   version.pl\n\nno changes added to commit (use "git add" and/or "git commit -a")\n\nMon 23/11/2015-15:16:37.87 C:\\...\\work\\checkout\\slf4j+> git diff\ndiff --git a/.gitignore b/.gitignore\nold mode 100644\nnew mode 100755\ndiff --git a/LICENSE.txt b/LICENSE.txt\nold mode 100644\nnew mode 100755\ndiff --git a/TODO.txt b/TODO.txt\nold mode 100644\nnew mode 100755\ndiff --git a/codeStyle.xml b/codeStyle.xml\nold mode 100644\nnew mode 100755\ndiff --git a/pom.xml b/pom.xml\nold mode 100644\nnew mode 100755\ndiff --git a/version.pl b/version.pl\nold mode 100644\nnew mode 100755\n\nMon 23/11/2015-15:16:45.22 C:\\...\\work\\checkout\\slf4j+> git reset --hard HEAD\nHEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore\n\nMon 23/11/2015-15:16:47.42 C:\\...\\work\\checkout\\slf4j+> git clean -f\n\nMon 23/11/2015-15:16:53.49 C:\\...\\work\\checkout\\slf4j+> git stash save -u\nSaved working directory and index state WIP on SLF4J_1.5.3: 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore\nHEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore\n\nMon 23/11/2015-15:17:00.40 C:\\...\\work\\checkout\\slf4j+> git stash drop\nDropped refs/stash@{0} (cb4966e9b1e9c9d8daa79ab94edc0c1442a294dd)\n\nMon 23/11/2015-15:17:06.75 C:\\...\\work\\checkout\\slf4j+> git stash drop\nDropped refs/stash@{0} (e6c49c470f433ce344e305c5b778e810625d0529)\n\nMon 23/11/2015-15:17:08.90 C:\\...\\work\\checkout\\slf4j+> git stash drop\nNo stash found.\n\nMon 23/11/2015-15:17:15.21 C:\\...\\work\\checkout\\slf4j+> git checkout -- .\n\nMon 23/11/2015-15:22:00.68 C:\\...\\work\\checkout\\slf4j+> git checkout -f -- .\n\nMon 23/11/2015-15:22:04.53 C:\\...\\work\\checkout\\slf4j+> git status\nOn branch SLF4J_1.5.3\nChanges not staged for commit:\n  (use "git add ..." to update what will be committed)\n  (use "git checkout -- ..." to discard changes in working directory)\n\n        modified:   .gitignore\n        modified:   LICENSE.txt\n        modified:   TODO.txt\n        modified:   codeStyle.xml\n        modified:   pom.xml\n        modified:   version.pl\n\nno changes added to commit (use "git add" and/or "git commit -a")\n\nMon 23/11/2015-15:22:13.06 C:\\...\\work\\checkout\\slf4j+> git diff\ndiff --git a/.gitignore b/.gitignore\nold mode 100644\nnew mode 100755\ndiff --git a/LICENSE.txt b/LICENSE.txt\nold mode 100644\nnew mode 100755\ndiff --git a/TODO.txt b/TODO.txt\nold mode 100644\nnew mode 100755\ndiff --git a/codeStyle.xml b/codeStyle.xml\nold mode 100644\nnew mode 100755\ndiff --git a/pom.xml b/pom.xml\nold mode 100644\nnew mode 100755\ndiff --git a/version.pl b/version.pl\nold mode 100644\nnew mode 100755\n</pre>\n\n<p>The only way to fix this is to manually reset the permissions on the changed files:</p>\n\n<pre>\nMon 23/11/2015-15:25:43.79 C:\\...\\work\\checkout\\slf4j+> git status -s | egrep "^ M" | cut -c4- | for /f "usebackq tokens=* delims=" %A in (`more`) do chmod 644 %~A\n\nMon 23/11/2015-15:25:55.37 C:\\...\\work\\checkout\\slf4j+> git status\nOn branch SLF4J_1.5.3\nnothing to commit, working directory clean\n\nMon 23/11/2015-15:25:59.28 C:\\...\\work\\checkout\\slf4j+>\n\nMon 23/11/2015-15:26:31.12 C:\\...\\work\\checkout\\slf4j+> git diff\n\n</pre>\n'}, {'answer_id': 35214606, 'author': 'msangel', 'author_id': 449553, 'author_profile': 'https://Stackoverflow.com/users/449553', 'pm_score': 4, 'selected': False, 'text': '<p>No matter what state your repo is in you can always reset to any previous commit:</p>\n\n<pre><code>git reset --hard &lt;commit hash&gt;\n</code></pre>\n\n<hr>\n\n<p>This will discard all changes which were made after that commit.</p>\n'}, {'answer_id': 36924148, 'author': 'Martin G', 'author_id': 3545094, 'author_profile': 'https://Stackoverflow.com/users/3545094', 'pm_score': 7, 'selected': False, 'text': '<p>Since no answer suggests the exact option combination that I use, here it is:</p>\n<pre><code>git clean -dxn .  # dry-run to inspect the list of files-to-be-removed\ngit clean -dxf .  # REMOVE ignored/untracked files (in the current directory)\ngit checkout -- . # ERASE changes in tracked files (in the current directory)\n</code></pre>\n<p>This is the online help text for the used <code>git clean</code> options:</p>\n<p><code>-d</code></p>\n<p>Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use <code>-f</code> option twice if you really want to remove such a directory.</p>\n<p><code>-x</code></p>\n<p>Don’t use the standard ignore rules read from <code>.gitignore</code> (per directory) and <code>$GIT_DIR/info/exclude</code>, but do still use the ignore rules given with <code>-e</code> options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with <code>git reset</code>) to create a pristine working directory to test a clean build.</p>\n<p><code>-n</code></p>\n<p>Don’t actually remove anything, just show what would be done.</p>\n<p><code>-f</code></p>\n<p>If the Git configuration variable <code>clean.requireForce</code> is not set to <code>false</code>, Git clean will refuse to delete files or directories unless given <code>-f</code>, <code>-n</code>, or <code>-i</code>. Git will refuse to delete directories within the <code>.git</code> subdirectory or file, unless a second <code>-f</code> is given.</p>\n'}, {'answer_id': 37274801, 'author': 'Erdem ÖZDEMİR', 'author_id': 1836344, 'author_profile': 'https://Stackoverflow.com/users/1836344', 'pm_score': 6, 'selected': False, 'text': '<p>As you type git status, \n<strong>(use "git checkout -- ..." to discard changes in working directory)</strong>\nis shown.</p>\n\n<p>e.g. <code>git checkout -- .</code></p>\n'}, {'answer_id': 38367577, 'author': 'Lahiru Jayaratne', 'author_id': 1616697, 'author_profile': 'https://Stackoverflow.com/users/1616697', 'pm_score': 4, 'selected': False, 'text': '<p>In my opinion,</p>\n\n<pre><code>git clean -df\n</code></pre>\n\n<p>should do the trick. As per <a href="https://git-scm.com/docs/git-clean/2.2.0">Git documentation on git clean</a></p>\n\n<blockquote>\n  <p>git-clean - Remove untracked files from the working tree</p>\n</blockquote>\n\n<p><strong>Description</strong> </p>\n\n<blockquote>\n  <p>Cleans the working tree by recursively removing files that\n  are not under version control, starting from the current directory.</p>\n  \n  <p>Normally, only files unknown to Git are removed, but if the -x option\n  is specified, ignored files are also removed. This can, for example,\n  be useful to remove all build products.</p>\n  \n  <p>If any optional ... arguments are given, only those paths are\n  affected.</p>\n</blockquote>\n\n<p><strong>Options</strong></p>\n\n<blockquote>\n  <p>-d Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is\n  not removed by default. Use -f option twice if you really want to\n  remove such a directory.</p>\n  \n  <p>-f\n  --force If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f, -n or -i.</p>\n</blockquote>\n'}, {'answer_id': 39383786, 'author': 'Ben Wilde', 'author_id': 2284031, 'author_profile': 'https://Stackoverflow.com/users/2284031', 'pm_score': 5, 'selected': False, 'text': '<p>Just use:</p>\n\n<pre><code>git stash -u\n</code></pre>\n\n<p>Done. Easy.</p>\n\n<p>If you <em>really</em> care about your stash stack then you can follow with <code>git stash drop</code>. But at that point you\'re better off using (from Mariusz Nowak):</p>\n\n<pre><code>git checkout -- .\ngit clean -df\n</code></pre>\n\n<p>Nonetheless, I like <code>git stash -u</code> the best because it "discards" all tracked and untracked changes in just <em>one command</em>. Yet <code>git checkout -- .</code> only discards tracked changes,\nand <code>git clean -df</code> only discards untracked changes... and typing both commands is <em>far</em> too much work :)</p>\n'}, {'answer_id': 41305623, 'author': 'Xaree Lee', 'author_id': 1282160, 'author_profile': 'https://Stackoverflow.com/users/1282160', 'pm_score': 1, 'selected': False, 'text': "<p>Just use:</p>\n\n<pre><code>git stash -k -u\n</code></pre>\n\n<p>This will stash <strong>unstaged changes</strong> and <strong>untracked files (new files)</strong> and keep staged files.</p>\n\n<p>It's better than <code>reset</code>/<code>checkout</code>/<code>clean</code>, because you might want them back later (by <code>git stash pop</code>). Keeping them in the stash is better than discarding them.</p>\n"}, {'answer_id': 42112496, 'author': 'SDV', 'author_id': 1138573, 'author_profile': 'https://Stackoverflow.com/users/1138573', 'pm_score': 3, 'selected': False, 'text': '<p>I had a weird situation where a file is always unstaged, this helps me to resolve.</p>\n\n<blockquote>\n  <p>git rm .gitattributes<br>\n  git add -A<br>\n  git reset --hard </p>\n</blockquote>\n'}, {'answer_id': 43365551, 'author': 'Forhadul Islam', 'author_id': 1467428, 'author_profile': 'https://Stackoverflow.com/users/1467428', 'pm_score': 6, 'selected': False, 'text': '<p>The easiest way to do this is by using this command:</p>\n\n<p>This command is used to discard changes in working directory -</p>\n\n<pre><code>git checkout -- .\n</code></pre>\n\n<p><a href="https://git-scm.com/docs/git-checkout" rel="noreferrer">https://git-scm.com/docs/git-checkout</a> </p>\n\n<p>In git command, stashing of untracked files is achieved by using:</p>\n\n<pre><code>git stash -u\n</code></pre>\n\n<p><a href="http://git-scm.com/docs/git-stash" rel="noreferrer">http://git-scm.com/docs/git-stash</a></p>\n'}, {'answer_id': 44361801, 'author': 'Pau', 'author_id': 4751165, 'author_profile': 'https://Stackoverflow.com/users/4751165', 'pm_score': 3, 'selected': False, 'text': '<p>You could create your own alias which describes how to do it in a descriptive way.</p>\n\n<p>I use the next alias to discard changes.</p>\n\n<hr>\n\n<h3>Discard changes in a (list of) file(s) in working tree</h3>\n\n<pre><code>discard = checkout --\n</code></pre>\n\n<p>Then you can use it as next to discard all changes:</p>\n\n<pre><code>discard .\n</code></pre>\n\n<p>Or just a file:</p>\n\n<pre><code>discard filename\n</code></pre>\n\n<hr>\n\n<p>Otherwise, if you want to discard all changes and also the untracked files, I use a mix of checkout and clean:</p>\n\n<h3>Clean and discard changes and untracked files in working tree</h3>\n\n<pre><code>cleanout = !git clean -df &amp;&amp; git checkout -- .\n</code></pre>\n\n<p>So the use is simple as next:</p>\n\n<pre><code>cleanout\n</code></pre>\n\n<hr>\n\n<p>Now is available in the next Github repo which contains a lot of aliases:</p>\n\n<ul>\n<li><a href="https://github.com/GitAlias/gitalias" rel="noreferrer">https://github.com/GitAlias/gitalias</a></li>\n</ul>\n'}, {'answer_id': 45420441, 'author': 'Jesús Castro', 'author_id': 2212414, 'author_profile': 'https://Stackoverflow.com/users/2212414', 'pm_score': 3, 'selected': False, 'text': "<p>If it's almost impossible to rule out modifications of the files, have you considered ignoring them? If this statement is right and you wouldn't touch those files during your development, this command may be useful: </p>\n\n<p><code>git update-index --assume-unchanged file_to_ignore</code></p>\n"}, {'answer_id': 49343276, 'author': '2540625', 'author_id': 2540625, 'author_profile': 'https://Stackoverflow.com/users/2540625', 'pm_score': 6, 'selected': False, 'text': '<p>If you merely wish <strong>to remove changes to existing files</strong>, use <code>checkout</code> (<a href="https://git-scm.com/docs/git-checkout" rel="noreferrer">documented here</a>). </p>\n\n<pre><code>git checkout -- .\n</code></pre>\n\n<ul>\n<li>No branch is specified, so it checks out the current branch. </li>\n<li>The double-hyphen (<code>--</code>) tells Git that what follows should be taken as its second argument (path), that you skipped specification of a branch.</li>\n<li>The period (<code>.</code>) indicates all paths. </li>\n</ul>\n\n<p>If you want <strong>to remove files added</strong> since your last commit, use <code>clean</code> (<a href="https://git-scm.com/docs/git-clean" rel="noreferrer">documented here</a>): </p>\n\n<pre><code>git clean -i \n</code></pre>\n\n<ul>\n<li>The <code>-i</code> option initiates an interactive <code>clean</code>, to prevent mistaken deletions. </li>\n<li>A handful of other options are available for a quicker execution; see the documentation. </li>\n</ul>\n\n<p>If you wish <strong>to move changes to a holding space for later access</strong>, use <code>stash</code> (<a href="https://git-scm.com/docs/git-stash" rel="noreferrer">documented here</a>): </p>\n\n<pre><code>git stash\n</code></pre>\n\n<ul>\n<li>All changes will be moved to Git\'s Stash, for possible later access. </li>\n<li>A handful of options are available for more nuanced stashing; see the documentation. </li>\n</ul>\n'}, {'answer_id': 56870406, 'author': 'SANGEETHA P.H.', 'author_id': 7510315, 'author_profile': 'https://Stackoverflow.com/users/7510315', 'pm_score': 5, 'selected': False, 'text': '<p>To do a permanent discard:\n<code>git reset --hard</code></p>\n\n<p>To save changes for later:\n<code>git stash</code></p>\n'}, {'answer_id': 57670112, 'author': 'Khem Raj Regmi', 'author_id': 5591577, 'author_profile': 'https://Stackoverflow.com/users/5591577', 'pm_score': 4, 'selected': False, 'text': '<p>you have a very simple git command <code>git checkout .</code></p>\n'}, {'answer_id': 57880896, 'author': 'prosoitos', 'author_id': 9210961, 'author_profile': 'https://Stackoverflow.com/users/9210961', 'pm_score': 8, 'selected': False, 'text': '<h3>2019 update</h3>\n<p>You can now discard unstaged changes in <strong>one tracked file</strong> with:</p>\n<pre><code>git restore &lt;file&gt;\n</code></pre>\n<p>and in <strong>all tracked files</strong> in the current directory (recursively) with:</p>\n<pre><code>git restore .\n</code></pre>\n<p>If you run the latter from the root of the repository, it will discard unstaged changes in all tracked files in the project.</p>\n<h3>Notes</h3>\n<ul>\n<li><code>git restore</code> was introduced in <a href="https://github.com/git/git/commit/f496b064fc1135e0dded7f93d85d72eb0b302c22" rel="noreferrer">July 2019</a> and released in version 2.23 as part of a split of the <code>git checkout</code> command into <code>git restore</code> for files and <code>git switch</code> for branches.</li>\n<li><code>git checkout</code> still behaves as it used to and the older answers remain perfectly valid.</li>\n<li>When running <code>git status</code> with unstaged changes in the working tree, this is now what Git suggests to use to discard them (instead of <code>git checkout -- &lt;file&gt;</code> as it used to prior to v2.23).</li>\n<li>As with <code>git checkout -- .</code>, this only discards changes in tracked files. So <a href="https://stackoverflow.com/a/12184274/9210961">Mariusz Nowak\'s answer</a> still applies and if you want to discard all unstaged changes, including untracked files, you could run, as he suggests, an additional <code>git clean -df</code>.</li>\n</ul>\n'}, {'answer_id': 63950139, 'author': 'The Schwartz', 'author_id': 1369474, 'author_profile': 'https://Stackoverflow.com/users/1369474', 'pm_score': 3, 'selected': False, 'text': "<p>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:</p>\n<p>(use &quot;git add ...&quot; to update what will be committed)</p>\n<p>(use &quot;git restore ...&quot; to discard changes in working directory)</p>\n<p>So git 'restore' is the modern solution to this. It is always a good idea to read the suggestions from git after typing 'git status' :-)</p>\n"}, {'answer_id': 68304651, 'author': 'Fairoz', 'author_id': 5497822, 'author_profile': 'https://Stackoverflow.com/users/5497822', 'pm_score': 2, 'selected': False, 'text': '<p>If you want to restore unstaged files use\ngit restore --staged .</p>\n'}, {'answer_id': 73040730, 'author': 'G-Man', 'author_id': 4616126, 'author_profile': 'https://Stackoverflow.com/users/4616126', 'pm_score': 3, 'selected': False, 'text': "<pre><code>git checkout .\n</code></pre>\n<p>This will discard any uncommitted changes to the branch.  It won't reset it back if any changes were committed.  This is handy when you've done some changes and decide you don't want them for some reason and you have NOT committed those changes. It actually just checks out the branch again and discards any current uncommitted changes.</p>\n<p>( must be in the app's root or home dir for this to work )</p>\n"}, {'answer_id': 73620948, 'author': 'Cary', 'author_id': 250428, 'author_profile': 'https://Stackoverflow.com/users/250428', 'pm_score': -1, 'selected': False, 'text': "<p>To delete unstaged changes I tried &quot;git restore .&quot; as I was told by Git but it just didn't work. A very good way is to use:</p>\n<pre><code>git revert --hard\n</code></pre>\n<p>It works perfectly. Its Git Help explains perfectly the point:</p>\n<blockquote>\n<p><strong>--hard</strong>\nResets the index and working tree. <strong>Any changes to tracked files in the working tree since  are discarded.</strong> Any untracked files or directories in the way of writing any tracked files are simply deleted.</p>\n</blockquote>\n<p>PS: I am using git version 2.35.3.windows.1. I think quite some answers here made the issue over-complicated.</p>\n"}, {'answer_id': 74261094, 'author': 'Mohamed Eldefrawy', 'author_id': 6627676, 'author_profile': 'https://Stackoverflow.com/users/6627676', 'pm_score': 0, 'selected': False, 'text': '<p>To discard changes in working directory use\n<code>git checkout -- &lt;file&gt;</code>\n<strong>--</strong> means changes in current branch\nreferences:-</p>\n<ul>\n<li><a href="https://www.baeldung.com/git-discard-unstaged-changes" rel="nofollow noreferrer">https://www.baeldung.com/git-discard-unstaged-changes</a></li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/52704', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4883/']