Skip to main content
add clarification about staged changes
Source Link
Nagev
  • 13.7k
  • 6
  • 78
  • 89

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).

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.

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).

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).

flip the answers to have more current versions of git at the top
Source Link
Nagev
  • 13.7k
  • 6
  • 78
  • 89

For all unstagedunstaged files in current working directory use:

git checkout --restore . 

For a specific file use:

git checkout --restore path/to/file/to/revert 

That together with --git switch here to remove ambiguityreplaces the overloaded git checkout (this is known as argument disambiguationsee here), and thus removes the argument disambiguation.

Before Git 2.23

For Git 2.23 onwards, one may want to use the more specificall unstaged files in current working directory:

git restorecheckout -- . 

resp.For a specific file:

git restorecheckout -- path/to/file/to/revert 

that together with git switch replaces the overloaded git checkout-- here to remove ambiguity (see herethis is known as argument disambiguation), and thus removes the argument disambiguation.

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 ambiguity (this is known as argument disambiguation).

For Git 2.23 onwards, one may want to use the more specific

git restore . 

resp.

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.

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.

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).

changed mistake of saying "remove disambiguiation" (when it should be remove ambiguity)
Source Link

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 ambiguity (this is known as argument disambiguation).

For Git 2.23 onwards, one may want to use the more specific

git restore . 

resp.

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.

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 disambiguation.

For Git 2.23 onwards, one may want to use the more specific

git restore . 

resp.

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.

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 ambiguity (this is known as argument disambiguation).

For Git 2.23 onwards, one may want to use the more specific

git restore . 

resp.

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.

Loading
Bounty Awarded with 300 reputation awarded by CommunityBot
Loading
edited body
Source Link
Flow
  • 24.1k
  • 15
  • 106
  • 159
Loading
Rollback to Revision 2
Source Link
user456814
user456814
Loading
code formatted to highlight the period(.) sign at the end
Source Link
Loading
added the command git checkout -- . command that has 17 & 10 upvotes in the comments.
Source Link
Amir
  • 9.2k
  • 5
  • 37
  • 46
Loading
Source Link
Tobi
  • 82.6k
  • 6
  • 35
  • 37
Loading