How do I discard changes in my working copy that are not in the index?
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 a git stash drop
command if you like.
git reset
command will discard changes in the index too. –
Preestablish git stash
, nor any variety of git checkout
will discard unstaged deletes. According to the output of git status
, the actual correct answer here is some flavor git reset HEAD
–
Klingensmith git checkout -- .
does the job with one command only. –
Gav stash save --keep-index --include-untracked
and use the stash as a recycle bin so you can always easily restore your changes if cleaning them up was a mistake. –
Refluent git clean
has a dry-run option, -n
–
Opera save
option is deprecated in favour of git stash push
. It differs from "stash push" in that it cannot take pathspecs, and any non-option arguments form the message. git-scm.com –
Schulte stash save --keep-index --include-untracked
: How would you restore the changes if you realise that cleaning up was a mistake? –
Humo git stash save && git stash drop
is unusable as a general scripting solution, since it will not work (or do nasty things) if there's nothing to stash (and may drop a stash you may have wanted to keep). git checkout-index -afq && git clean -fdqx
is the real deal! –
Bittencourt For all unstaged files in current working directory use:
git restore .
For a specific file use:
git restore path/to/file/to/revert
That together with git switch
replaces the overloaded git checkout
(see here), and thus removes the argument disambiguation.
If a file has both staged and unstaged changes, only the unstaged changes shown in git diff
are reverted. Changes shown in git diff --staged
stay intact.
Before Git 2.23
For all unstaged files in current working directory:
git checkout -- .
For a specific file:
git checkout -- path/to/file/to/revert
--
here to remove ambiguity (this is known as argument disambiguation).
git status
–
Boding error: The following untracked working tree files would be overwritten by checkout: ...
. –
Jenniejennifer git checkout -- .
means the same thing as git checkout .
, except that you're explicit about the fact that you're not specifying the branch name. They both say checkout the HEAD version on the branch I am currently on for '.' or './'. If you do git checkout branch-name directory-or-file-name
in general, you get the HEAD version of directory-or-file-name
on branch branch-name
. –
Gavrah git checkout .
is shorter –
Holy git checkout HEAD
does not actually discard the changes for me, so stash
based solution is still preferred. –
Amygdalate git checkout
otherwise it will not kill changes you made! The trick with .
is that a checkout with path also includes all subdirectories. –
Sire git clean -- .
should do what I wanted it to do. Reading this answer and testing it confirmed it. But for some reason, IT DOESN'T WORK IN SUBMODULES! Why not? <sigh> –
Gracegraceful git stash save --keep-index
solution, because it creates a commit. Even if I do a git stash drop
immediately after the stash save
the commit can still be restored. So the git stash save ...
solution is safer just in case you discarded too much. E.g. using https://mcmap.net/q/11480/-how-do-i-recover-a-dropped-stash-in-git –
Finance git checkout -- path/to/file/to/revert
? –
Machination git checkout -- :/
(I was looking for this myself!) –
Maishamaisie git add <filename>
? –
Jaimiejain git restore
and it is the one now given by git status
. See my 2019 update –
Clubhaul git checkout -f -- path/to/revert/
whereas this does NOT work git checkout -f -- path/to/revert/*
as any new files git doesn't have a record of. –
Evvoia git status
doesn't always suggest a way to discard unstaged files. It isn't doing so for me (git 2.23.0). It does suggest using "git restore --staged <file>..." to unstage
staged files. –
Aragon git restore .
) doesn't discard all unstaged files in the current working directory. In particular it doesn't discard new, untracked files. Just tested in git 2.23.0. The new untracked files are still there. –
Aragon 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 a git stash drop
command if you like.
git reset
command will discard changes in the index too. –
Preestablish git stash
, nor any variety of git checkout
will discard unstaged deletes. According to the output of git status
, the actual correct answer here is some flavor git reset HEAD
–
Klingensmith git checkout -- .
does the job with one command only. –
Gav stash save --keep-index --include-untracked
and use the stash as a recycle bin so you can always easily restore your changes if cleaning them up was a mistake. –
Refluent git clean
has a dry-run option, -n
–
Opera save
option is deprecated in favour of git stash push
. It differs from "stash push" in that it cannot take pathspecs, and any non-option arguments form the message. git-scm.com –
Schulte stash save --keep-index --include-untracked
: How would you restore the changes if you realise that cleaning up was a mistake? –
Humo git stash save && git stash drop
is unusable as a general scripting solution, since it will not work (or do nasty things) if there's nothing to stash (and may drop a stash you may have wanted to keep). git checkout-index -afq && git clean -fdqx
is the real deal! –
Bittencourt It seems like the complete solution is:
git clean -df
git checkout -- .
WARNING: while it won't delete ignored files mentioned directly in .gitignore, git clean -df
may delete ignored files residing in folders.
git clean
removes all untracked files and git checkout
clears all unstaged changes.
git reset --hard
–
Persons -- .
? Does it say checkout current last commit to current folder? –
Leschen .gitignore
d. –
Many git -df
works, I recommend adding the n
option if you are still new to running the command, i.e. git -dfn
. This will run it in dry-run
mode so you can see what will get deleted without it actually deleting and doing anything. If you are okay with the result, you would run it again without the n
option. –
Faze git clean
, options and usage: atlassian.com/git/tutorials/undoing-changes/git-clean –
Instanter --hard
/--soft
resets by path. –
Glossary git clean -df
and git checkout-index -fa
is much better. I think git checkout-index -fa
produces a more-desirable result than git checkout -- .
. I've added these commands, with thorough explanations, to my answer here: Using git, how do you reset the working tree (local file system state) to the state of the index (“staged” files)?. –
Glossary git clean -i
to run in interactive mode. That should help prevent the deletion of config files and the like. –
Calliper git clean -df
already worked for me –
Yaroslavl 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, overwriting working tree files.
git checkout-index -a -f
git stash save --keep-index
. –
Vivle git checkout --
does not work if you have only one branch. git checkout .
always works. –
Ammon git clean
to also remove untracked files. –
Bittencourt 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 files
-f
: Force (might be not necessary depending on clean.requireForce
setting)
Run git help clean
to see the manual
2019 update
You can now discard unstaged changes in one tracked file with:
git restore <file>
and in all tracked files in the current directory (recursively) with:
git restore .
If you run the latter from the root of the repository, it will discard unstaged changes in all tracked files in the project.
Notes
git restore
was introduced in July 2019 and released in version 2.23 as part of a split of thegit checkout
command intogit restore
for files andgit switch
for branches.git checkout
still behaves as it used to and the older answers remain perfectly valid.- When running
git status
with unstaged changes in the working tree, this is now what Git suggests to use to discard them (instead ofgit checkout -- <file>
as it used to prior to v2.23). - As with
git checkout -- .
, this only discards changes in tracked files. So Mariusz Nowak's answer still applies and if you want to discard all unstaged changes, including untracked files, you could run, as he suggests, an additionalgit clean -df
.
git restore .
worked perfectly. Thanks. –
Edmonson git restore <filename>
and it worked perfectly. –
Cecrops git restore .
restores all files in current directory, not in the whole repository. –
Lyon git commit -m "wip" && git reset --hard && git reset --soft HEAD~1 && git reset
. –
Merengue git status
without deleting untracked files that are in .gitignore
? –
Fachini git clean -idf
and select the relevant files, or you can write a bash script. –
Clubhaul My favorite is
git checkout -p
That lets you selectively revert chunks.
See also:
git add -p
-p
adds a nice extra layer of safety. Combine it with git clean -d
to actually answer OP. –
Tenet Since no answer suggests the exact option combination that I use, here it is:
git clean -dxn . # dry-run to inspect the list of files-to-be-removed
git clean -dxf . # REMOVE ignored/untracked files (in the current directory)
git checkout -- . # ERASE changes in tracked files (in the current directory)
This is the online help text for the used git clean
options:
-d
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 -f
option twice if you really want to remove such a directory.
-x
Don’t use the standard ignore rules read from .gitignore
(per directory) and $GIT_DIR/info/exclude
, but do still use the ignore rules given with -e
options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset
) to create a pristine working directory to test a clean build.
-n
Don’t actually remove anything, just show what would be done.
-f
If the Git configuration variable clean.requireForce
is not set to false
, Git clean will refuse to delete files or directories unless given -f
, -n
, or -i
. Git will refuse to delete directories within the .git
subdirectory or file, unless a second -f
is given.
git reset --hard
instead? (which is actually equivalent to git reset --hard HEAD
and should work whichever is the current directory...) –
Vu git clean -dfx
, here is a tip I use to be on the safe side before running it: just run git clean -d -x -n
before, to display the list of files-to-be-removed, then confirm the operation by running git clean -d -x -f
(I put the argument -n
, resp. -f
in the end to be able to quickly change it in a terminal) –
Vu .gitignore
you will lose them. So consider backing up your project before this. –
Estevez git status
without deleting untracked files that are in .gitignore
? –
Fachini If you merely wish to remove changes to existing files, use checkout
(documented here).
git checkout -- .
- No branch is specified, so it checks out the current branch.
- The double-hyphen (
--
) tells Git that what follows should be taken as its second argument (path), that you skipped specification of a branch. - The period (
.
) indicates all paths.
If you want to remove files added since your last commit, use clean
(documented here):
git clean -i
- The
-i
option initiates an interactiveclean
, to prevent mistaken deletions. - A handful of other options are available for a quicker execution; see the documentation.
If you wish to move changes to a holding space for later access, use stash
(documented here):
git stash
- All changes will be moved to Git's Stash, for possible later access.
- A handful of options are available for more nuanced stashing; see the documentation.
The easiest way to do this is by using this command:
This command is used to discard changes in working directory -
git checkout -- .
https://git-scm.com/docs/git-checkout
In git command, stashing of untracked files is achieved by using:
git stash -u
.
at the end. To future me: the period is essential! –
Nihi git clean -fd
to clean files not in the index. –
Lidia 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 the file, then you use
git checkout
. 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.git checkout -- foo.txt
If you have staged the file, then use git reset. Reset changes the index to match a commit.
git reset -- foo.txt
I suspect that using git stash
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.
Take a look at the article above for further advice.
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
As you type git status, (use "git checkout -- ..." to discard changes in working directory) is shown.
e.g. git checkout -- .
You can use git stash - if something goes wrong, you can still revert from the stash. Similar to some other answer here, but this one also removes all unstaged files and also all unstaged deletes:
git add .
git stash
if you check that everything is OK, throw the stash away:
git stash drop
The answer from Bilal Maqsood with git clean
also worked for me, but with the stash I have more control - if I do sth accidentally, I can still get my changes back
UPDATE
I think there is 1 more change (don't know why this worked for me before):
git add . -A
instead of git add .
without the -A
the removed files will not be staged
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 from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.
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.
So I do this to make sure they don't sit there when I git reset (later - excludes gitignores on the Origin/branchname)
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).
git add --all
Then I
git fetch --all
Then I reset to origin
git reset --hard origin/branchname
That will put it back to square one. Just like RE-Cloning the branch, WHILE keeping all my gitignored files locally and in place.
Updated per user comment below: Variation to reset the to whatever current branch the user is on.
git reset --hard @{u}
--untracked-files[=<mode>]
that untracked files are shown by default in git status
, and you can tell it not to show them if it bothers you! For the record, git add --all
will stage the files ready for commit, at which point git recognises them (hence git reset --hard will then work). git clean
removes untracked files see here –
Bria git reset --hard @{u}
which resets the branch to wherever the current remote-tracking branch is –
Fabrice 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.
To do a permanent discard:
git reset --hard
To save changes for later:
git stash
Just use:
git stash -u
Done. Easy.
If you really care about your stash stack then you can follow with git stash drop
. But at that point you're better off using (from Mariusz Nowak):
git checkout -- .
git clean -df
Nonetheless, I like git stash -u
the best because it "discards" all tracked and untracked changes in just one command. Yet git checkout -- .
only discards tracked changes,
and git clean -df
only discards untracked changes... and typing both commands is far too much work :)
git stash -u
will soon (Git 2.14.x/2.15, Q3 2017) evolve a bit: https://mcmap.net/q/11482/-why-can-39-t-stash-be-applied-to-the-working-directory –
Mere git stash -k
in my opinion. –
Gowan simply say
git stash
It will remove all your local changes. You also can use later by saying
git stash apply
or git stash pop
No matter what state your repo is in you can always reset to any previous commit:
git reset --hard <commit hash>
This will discard all changes which were made after that commit.
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
git help clean
"-d Remove untracked directories in addition to untracked files." –
Soapbox cd path_to_project_folder # take you to your project folder/working directory
git checkout . # removes all unstaged changes in working directory
Final working solution
git restore .
git clean -f
git clean -df (if you have folders in your local changes)
In my opinion,
git clean -df
should do the trick. As per Git documentation on git clean
git-clean - Remove untracked files from the working tree
Description
Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.
Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for example, be useful to remove all build products.
If any optional ... arguments are given, only those paths are affected.
Options
-d 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 -f option twice if you really want to remove such a directory.
-f --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.
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.
This technique is useful when, for some reason, you can't easily delete all of the untracked files by some ordinary mechanism (like rm).
I had a weird situation where a file is always unstaged, this helps me to resolve.
git rm .gitattributes
git add -A
git reset --hard
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:
git update-index --assume-unchanged file_to_ignore
git checkout .
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.
( must be in the app's root or home dir for this to work )
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 read the warnings on github.
I had a similar problem, perhaps not identical, and I'm sad to say my solution is not ideal, but it is ultimately effective.
I would often have git status messages like this (involving at least 2/4 files):
$ git status
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2var.dats
# modified: doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2var.dats
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2Var.dats
# modified: doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2Var.dats
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.
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. 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.
You could create your own alias which describes how to do it in a descriptive way.
I use the next alias to discard changes.
Discard changes in a (list of) file(s) in working tree
discard = checkout --
Then you can use it as next to discard all changes:
discard .
Or just a file:
discard filename
Otherwise, if you want to discard all changes and also the untracked files, I use a mix of checkout and clean:
Clean and discard changes and untracked files in working tree
cleanout = !git clean -df && git checkout -- .
So the use is simple as next:
cleanout
Now is available in the next Github repo which contains a lot of aliases:
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 .
# (later you can re-apply the diff:)
git apply ~/mijn-fix.diff
[edit] as commented, it ís possible to name stashes. Well, use this if you want to share your stash ;)
git stash save "Feature X work in progress"
. –
Samala If you are in case of submodule and no other solutions work try:
To check what is the problem (maybe a "dirty" case) use:
git diff
To remove stash
git submodule update
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 "git restore ..." to discard changes in working directory)
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' :-)
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: Branch, Reset, Yes!
So what I often do in practice to revert unwanted local changes is to commit all the good stuff, and then reset the branch.
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.
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.
So in summary, I simply do commit, branch reset, and amend last commit.
If you want to restore unstaged files use git restore --staged .
None of the solutions work if you just changed the permissions of a file (this is on DOS/Windoze)
Mon 23/11/2015-15:16:34.80 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:16:37.87 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755 Mon 23/11/2015-15:16:45.22 C:\...\work\checkout\slf4j+> git reset --hard HEAD HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:16:47.42 C:\...\work\checkout\slf4j+> git clean -f Mon 23/11/2015-15:16:53.49 C:\...\work\checkout\slf4j+> git stash save -u Saved working directory and index state WIP on SLF4J_1.5.3: 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:17:00.40 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (cb4966e9b1e9c9d8daa79ab94edc0c1442a294dd) Mon 23/11/2015-15:17:06.75 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (e6c49c470f433ce344e305c5b778e810625d0529) Mon 23/11/2015-15:17:08.90 C:\...\work\checkout\slf4j+> git stash drop No stash found. Mon 23/11/2015-15:17:15.21 C:\...\work\checkout\slf4j+> git checkout -- . Mon 23/11/2015-15:22:00.68 C:\...\work\checkout\slf4j+> git checkout -f -- . Mon 23/11/2015-15:22:04.53 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:22:13.06 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755
The only way to fix this is to manually reset the permissions on the changed files:
Mon 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 Mon 23/11/2015-15:25:55.37 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 nothing to commit, working directory clean Mon 23/11/2015-15:25:59.28 C:\...\work\checkout\slf4j+> Mon 23/11/2015-15:26:31.12 C:\...\work\checkout\slf4j+> git diff
Just use:
git stash -k -u
This will stash unstaged changes and untracked files (new files) and keep staged files.
It's better than reset
/checkout
/clean
, because you might want them back later (by git stash pop
). Keeping them in the stash is better than discarding them.
To discard changes in working directory use
git checkout -- <file>
-- means changes in current branch
references:-
git checkout
is obsolete since Git 2.23 (Q3 2019). You would use git restore -- .
now (in complement git git clean -df
) –
Mere git checkout
…), you answer is subsumed by previous ones, e.g. @MartinG's one; and for the new syntax (git restore
…), see also the answer @Mere mentioned. –
Vu © 2022 - 2024 — McMap. All rights reserved.
git-clean
only removes untracked files from the working tree git-scm.com/docs/git-clean – Possgit-clean -df
can be dangerous. It will delete local untracked files (e.g. covered by a .gitignore) Read all below carefully and consider git checkout . instead – Antoniettaantoningit status
gives a suggestion on how to do that!git checkout -- .
– Eastboundgit reset HEAD file1
that overwritesfile1
from most recent commit in commit History.to Staging area. – Weizmanngit status
gives the suggestion:git restore
.git restore
is a new command exactly for this purpose. See my 2019 update. – Clubhaul