Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fork not in sync with local clone with error, and cannot pull with rebase? [duplicate]

How do I discard changes in my working copy that are not in the index?

like image 447
readonly Avatar asked Nov 21 '22 02:11

readonly


2 Answers

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

like image 62
Tobi Avatar answered Nov 22 '22 15:11

Tobi


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.

like image 41
Greg Hewgill Avatar answered Nov 22 '22 16:11

Greg Hewgill