Quantcast
Channel: How do I discard unstaged changes in Git? - Stack Overflow
Browsing latest articles
Browse All 42 View Live

Answer by prosoitos for How do I discard unstaged changes in Git?

2019 update: Since July 2019, there has been a new command which does exactly this: git restore. In git status, now Git recommends using this command instead of git checkout as it used to. While this...

View Article



Answer by khem raj regmi for How do I discard unstaged changes in Git?

you have a very simple git command git checkout .

View Article

Answer by SANGEETHA P.H. for How do I discard unstaged changes in Git?

To do a permanent discard: git reset --hard To save changes for later: git stash

View Article

Answer by jtheletter for How do I discard unstaged changes in Git?

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

View Article

Answer by Jesús Castro for How do I discard unstaged changes in Git?

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

View Article


Answer by Pau for How do I discard unstaged changes in Git?

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

View Article

Answer by A H M Forhadul Islam for How do I discard unstaged changes in Git?

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

View Article

Answer by SDV for How do I discard unstaged changes in Git?

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

View Article


Answer by 李岡諭 for How do I discard unstaged changes in Git?

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

View Article


Answer by Ben Wilde for How do I discard unstaged changes in Git?

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

View Article

Answer by Lahiru for How do I discard unstaged changes in Git?

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

View Article

Answer by Erdem ÖZDEMİR for How do I discard unstaged changes in Git?

As you type git status, (use "git checkout -- ..." to discard changes in working directory) is shown. e.g. git checkout -- .

View Article

Answer by Martin G for How do I discard unstaged changes in Git?

Since no answer suggests the exact option combination that I use, here it is: git clean -dfx git checkout . This is the online help text for the used git clean options: -d Remove untracked directories...

View Article


Answer by msangel for How do I discard unstaged changes in Git?

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.

View Article

Answer by Malcolm Boekhoff for How do I discard unstaged changes in Git?

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

View Article


Answer by onalbi for How do I discard unstaged changes in Git?

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

View Article

Answer by Asped for How do I discard unstaged changes in Git?

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

View Article


Answer by Nick for How do I discard unstaged changes in Git?

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

View Article

Answer by piyushmandovra for How do I discard unstaged changes in Git?

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

View Article

Answer by Ivan for How do I discard unstaged changes in Git?

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

View Article

Answer by Ben for How do I discard unstaged changes in Git?

My favorite is git checkout -p That lets you selectively revert chunks. See also: git add -p

View Article


Answer by vivekporwal04 for How do I discard unstaged changes in Git?

cd path_to_project_folder # take you to your project folder/working directory git checkout . # removes all unstaged changes in working directory

View Article


Answer by Bijan for How do I discard unstaged changes in Git?

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

View Article

Answer by bbarker for How do I discard unstaged changes in Git?

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

View Article

Answer by GlassGhost for How do I discard unstaged changes in Git?

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

View Article


Answer by twicejr for How do I discard unstaged changes in Git?

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

View Article

Answer by Mariusz Nowak for How do I discard unstaged changes in Git?

It seems like the complete solution is: git clean -df git checkout -- . git clean removes all untracked files (warning: while it won't delete ignored files mentioned directly in .gitignore, it may...

View Article

Answer by blak3r for How do I discard unstaged changes in Git?

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

View Article

Answer by tjb for How do I discard unstaged changes in Git?

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

View Article



Answer by Elvis Ciotti for How do I discard unstaged changes in Git?

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

View Article

Answer by artur for How do I discard unstaged changes in Git?

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.

View Article

Answer by Joshua Kunzmann for How do I discard unstaged changes in Git?

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

View Article

Answer by CB Bailey for How do I discard unstaged changes in Git?

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

View Article


Answer by Greg Hewgill for How do I discard unstaged changes in Git?

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

View Article

Answer by Tobi for How do I discard unstaged changes in Git?

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

View Article

How do I discard unstaged changes in Git?

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

View Article


Answer by The Schwartz for How do I discard unstaged changes in Git?

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

View Article


Answer by Fairoz for How do I discard unstaged changes in Git?

If you want to restore unstaged files usegit restore --staged .

View Article

Answer by Mohamed Eldefrawy for How do I discard unstaged changes in Git?

To discard changes in working directory usegit checkout -- <file>-- means changes in current branchreferences:-https://www.baeldung.com/git-discard-unstaged-changes

View Article

Answer by Cary for How do I discard unstaged changes in Git?

To delete unstaged changes I tried "git restore ." as I was told by Git but it just didn't work. A very good way is to use:git revert --hardIt works perfectly. Its Git Help explains perfectly the...

View Article

Answer by G-Man for How do I discard unstaged changes in Git?

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

View Article


Answer by Choletski for How do I discard unstaged changes in Git?

Final working solutiongit restore .git clean -f git clean -df (if you have folders in your local changes)

View Article
Browsing latest articles
Browse All 42 View Live




Latest Images