Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Shell: How can we remove specific file from untracked files

I wish to delete a specific file from untracked files in git using shell command. but as i have searched there is a solution only for like

-f - force, 
-d - directories too, 
-x - remove ignored files too.

let consider file as like gitignore.gitignore, Am failed whenever i tried the command git rm gitignore.gitignore for this concern. would appreciate any expected result.

like image 903
Raju Avatar asked Jul 25 '16 09:07

Raju


People also ask

How do I remove a file from git tracking?

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.


2 Answers

You may use the interactive mode with the flag -i in the following way

git clean -id`

(d is for directories as well) and then you can choose to iterate over the file and folders by pressing a, and choose what you want and do not want to delete.

like image 134
cerebrou Avatar answered Oct 16 '22 01:10

cerebrou


Might just need a git clean -df -n is handy to double check what you're doing first.

NAME
       git-clean - Remove untracked files from the working tree

OPTIONS
       -d
           Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if
           you really want to remove such a directory.

       -f, --force
           If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete
           directories with .git sub directory or file unless a second -f is given.

       -n, --dry-run
           Don't actually remove anything, just show what would be done.

However, if you've got uncommited changes you'd need to use git checkout -- .

like image 21
Adam Avatar answered Oct 16 '22 00:10

Adam