Git: How to ignore all existing irreproducible files?

Is there any convenient way to ignore all raw files and folders in git repository?
(I know about .gitignore .)

So git status will again give a clean result.

+83
git gitignore
Jul 18 '12 at 13:35
source share
6 answers

As already mentioned, excluding from the state is simple:

 git status -uno # must be "-uno" , not "-u no" 

If you want to constantly ignore currently unplayable files, you can, starting from the root of your project, run:

 git status --porcelain | grep '^??' | cut -c4- >> .gitignore 

Each subsequent call to git status will explicitly ignore these files.

UPDATE : the above command has a minor flaw: if you don't have a .gitignore file, but your gitignore will ignore itself! This is because the .gitignore file is created before git status --porcelain . Therefore, if you do not have a .gitignore file, I recommend using:

 echo "$(git status --porcelain | grep '^??' | cut -c4-)" > .gitignore 

This creates a subshell that completes before the .gitignore file is .gitignore .

ANNOUNCEMENT ANNOUNCEMENT , as I get a lot of votes (thanks!) I think I better explain the command a bit:

  • git status --porcelain used instead of git status --short because manual states: "Give the result in a format that is easy to parse scripts. This seems like a short output, but will remain stable in git versions and regardless of user configuration." Thus, we have both syntactic processing and stability;
  • grep '^??' only filters lines starting with ?? which according to git status instruction correspond to inappropriate files;
  • cut -c4- removes the first 3 characters of each line, which gives us only the relative path to the raw file;
  • Symbols | pipe , which pass the output of the previous command to the input of the following command:
  • the >> and > characters redirect operators that add the result of the previous command to the file or overwrite / create a new file, respectively.

ANOTHER OPTION for those who prefer using sed instead of grep and cut , here is another way:

 git status --porcelain | sed -n -e 's/^?? //p' >> .gitignore 
+194
Feb 28 '13 at 17:36
source share

If you want to constantly ignore these files, an easy way to add them to .gitignore :

 git ls-files --others --exclude-standard >> .gitignore 
+29
Jan 10 '16 at 17:57
source share

Found in manual

git status -uno

+10
Jul 18 '12 at 13:40
source share

-u no also uninstalled files are not displayed. -uno works as desired and shows uninstalled, but hides the unsung.

+5
Jul 17 '14 at 13:57
source share

Two ways:

use the "-uno" argument for git -status. Here is an example:

 [jenny@jenny_vmware:ft]$ git status # On branch ft # Untracked files: # (use "git add <file>..." to include in what will be committed) # # foo nothing added to commit but untracked files present (use "git add" to track) [jenny@jenny_vmware:ft]$ git status -uno # On branch ft nothing to commit (working directory clean) 

Or you can add files and directives to .gitignore, in which case they will never appear.

+2
Jul 18 2018-12-18T00:
source share

If you have a lot of unused files and don’t want to β€œ gitignore ” everyone, note that since git 1.8.3 (April 22, 2013) , git status will mention --untracked-files=no , even if you did not add this option first!

" git status " invites users to explore the possibility of using the --untracked=no option if it takes too much time.

+1
Apr 23 '13 at 8:07
source share



All Articles