How to remove local (untracked) files from the current Git working tree
Stack How?
Stackorigin – The Community of Question and Answers Latest Articles
Read More About Python List Comprehension with examples
Python List Comprehension: Python List comprehension provides a much more short syntax for creating a new list based on the values of an existing list. Advantages of List Comprehension in Python: Time Efficient than loop Space Efficient than loop Needs ...
Do not accept an offer letter from companies.
Do not accept an offer letter from companies without verifying the following points. Designation Salary Details & CTC Distribution Leave Policies Working Hours & Days Medical Coverage/Insurance Probation Period Notice Period Benefits and Perks Bonus F&F Policy
How to call API using Ajax
AJAX stands for Asynchronous JavaScript and XML and its used for to make calls to the server to fetch some data. In this article, we will learn how to implement a simple API call using AJAX technology. How to use GET ...
Simple Way to remove untracked files
To remove all untracked files, The simple way is to add all of them first and reset the repo as below
git add --all
,git stash
andgit stash drop
, try these three commands in this order inorder to remove all untracked files. By adding all those untracked files to git and stashing them will move all those untracked files to stash list and dropping out top one i.e., stash@{0} will remove the stashed changes from stash list.Use
git clean -f -d
to make sure that directories are also removed.or
-f
option twice if you really want to remove such a directory.You can then check if your files are really gone with
git status
.If needed to remove untracked files from particular subdirectory,
And combined way to delete untracked dir/files and ignored files.
after this you will have modified files only in
git status
.Remove all extra folders and files in this repo + submodules
This gets you in same state as fresh clone.
Remove all extra folders and files in this repo but not its submodules
Remove extra folders but not files (ex. build or logs folder)
Remove extra folders + ignored files (but not newly added files)
If file wasn’t ignored and not yet checked-in then it stays. Note the capital X.
New interactive mode
Be careful while running `git clean` command.
Always use
-n
before running the actual command as it will show you what files would get removed.By default,
git clean
will only remove untracked files that are not ignored. Any file that matches a pattern in your .gitignore or other ignore files will not be removed. If you want to remove those files too, you can add a-x
to the clean command.There is also interactive mode available
-i
with the clean commandAlternatively
If you are not 100% sure that deleting your uncommitted work is safe, you could use stashing instead
Before you use
stash --all
note: If the--all
option is used, then the ignored files are stashed and cleaned in addition to the untracked files.Stashing will also clear your directory but give you flexibility to retrieve the files at any point in time using stash with apply or pop. Then if you are fine with removing your stashed files you could run:
To see full instruction on how to work with stash see this How to name and retrieve a stash by name in git?