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.
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).
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.
I was trying to clean up git and use it in a better way, but the master is now so far from the branch I am working on, I will have to do it another way. The issue I am having is that I have made a couple of small changes just to get the site working locally to find that it is too far gone.
The issue now is git won't let me switch to a different branch without committing and I desparately do not under any circumstances want to do that. How can I just get rid of the changes, I don't need to stash them, I just need to get back to my work. In the past I have just had to delete the folder from my computer and clone it again from github, but there must be a way to just ignore the changes and checkout another branch. Any help would be appreciated I'm panicking currently and worried I'm about to lose 5 months of work because of git when I'm trying to learn how to use it.
I've tried:
git reset --hard HEAD
but that doesn't work
UPDATE: Thank you to all who responded to my post and apologies for lack of response, I have been on Annual Leave.
The upshot of all of this is that I need to learn git a lot better, so am just doing a course on linkedIn Learning so I don't get into this mess again. And for the record it just covered what I think I should have done:
"git log" - to find the last commit and copy SHA
"checkout -- SHA" - this lets git take you back to same status as last commit and reverts all unstaged changes.
There may well be a better or quicker way to do this, but this does it perfectly. And on a side note the course introduced me to the concept of atomic commits as a good practice.