React Remove Untracked Files
Git is the virtually mutual version control system, which stores the changes made to our project over fourth dimension in a specific database called a repository. We tin keep track of the changes fabricated to our project, and revert back to an earlier stage if anything is messed upward. In this tutorial, let'south have a look at how untracked files are removed from the current git working tree.
Steps to Setup a Basic Project
Stride 1: Create a folder named git
mkdir git
Stride 2: Switch to the git folder and create a binder named files
cd git mkdir files
Step 3: Create three files named tracked.txt, untracked.txt, and .gitignore in the git folder
touch tracked.txt untracked.txt .gitignore
Step 4: Create ii files in the files folder names file1.txt and file2.txt
cd files bear on file1.txt file2.txt
Step v: Create a .env file
impact .env
Footstep 6: Initialize an empty git repository using the following control
git init
Footstep vii: Add together .env to the .gitignore file
Step 8: Add the tracked.txt and .gitignore files to the staging area using the following control
git add tracked.txt .gitignore
Allow'southward become through each of the interactive commands one by one:
- clean: Removes the untracked files and directories and quits.
- filter by pattern: Lists all the files and directories that are going to be removed and asks the user for an input prompt in the form of a pattern to exclude files and directories from removal.
- select by numbers: Lists all the files and directories that are going to be removed and asks the user for an input prompt in the form of numbers that signal the file number to be excluded. The number can be comma-separated or separated by white infinite. Example: 5,8,ix or 5-ix or 5 8 ix.
- inquire each: Allows the user to ostend each file that is going to exist removed. Not every bit efficient as the in a higher place methods.
- quit: Quits the interactive manner without cleaning.
Project Construction
The projection structure will be similar to the below image.
At present that the basic projection structure is set up, let'south understand how untracked files are removed. Untracked files are those files that are absent from the latest snapshot of the git repository. We can remove untracked files from the electric current git working tree using the post-obit command
git make clean
No untracked files tin can be removed by running the git clean control without any flag. By running the git make clean command without any flags, a fatal mistake is generated and explicitly asks us to mention a flag
git clean without flags
List out the Files to be removed
To take a look at all the untracked files that will exist removed, nosotros can employ the git clean command with the -n flag. This lists out all the files that are going to be removed using the git clean command.
git clean -n
By running the control in our repository we go:
git clean with -n flag
List out the Files and Directories to be removed
To take a look at all the untracked files and untracked directories that will be removed, we can utilise the git clean command with the -n and -d flag. This lists out all the files and directories that are going to be removed using the git make clean control.
git make clean -northward -d
By running the command in our repository we go:
git clean with -n and -d flags
Remove the unstaged files
To remove the unstaged files, we take to employ the git clean control with the -f flag.
git clean -f
By running the command in our repository we get:
git clean with -f flag
Remove the unstaged files and the unstaged directories
To remove the unstaged files and the unstaged directories, we accept to use the git clean command with the -f and -d flags.
git clean -f -d
By running the control in our repository we get:
git clean with -f and -d flags
Remove the ignored files
To remove the untracked files and the files ignored past git, we have to utilise the git make clean command with the -f flag and -x flag
git clean -f -x
By running the command in our repository we get:
git clean with -f and -x flag
Remove all untracked files, directories, and ignored files
To remove all the untracked files, untracked directories, and ignored files, we have to employ the git clean command with the -fdx flag
git make clean -fdx
By running the command in our repository nosotros get:
Entering the interactive way
To enter an interactive git make clean mode, nosotros demand to use the git command flag with the -i flag
git make clean -i
By running the command in our repository we become:
git clean interactive manner
Source: https://www.geeksforgeeks.org/how-to-remove-local-untracked-files-from-current-git-working-tree/
0 Response to "React Remove Untracked Files"
Enviar um comentário