3

Intially to ignore the untracked files permanently I ran a

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

command. Now when I add a new file in my code, it is not showing in git status.

peterh
  • 11,875
  • 18
  • 85
  • 108
kumar
  • 41
  • 2
  • 1
    You can just manually edit the `.gitignore` file, or you can revert it back to a previous version using the commit history. See https://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git for the specifics of how to do that – Vlad274 May 30 '19 at 20:43
  • 1
    `git status` reports directories, not their files, if nothing in that directory is already tracked. Most likely, you are ignoring an entire directory, and your new files are in that directory. – j6t May 30 '19 at 20:44

2 Answers2

4

You have overwritten your .gitignore with the data of your changed files. A git status --porcelain output has no meaning in the syntax of the .gitignore.

You need to recover your .gitignore. The simplest way is - assuming you had no local, not committed change to it - is

git checkout -- .gitignore
peterh
  • 11,875
  • 18
  • 85
  • 108
1

If you want to add your files anyway, you have several options :

  • use git add -f file to disregard .gitignore and add the file anyway
  • edit the .gitignore file to remove the lines which should not be ignored

If you want to undo the changes that were applied to .gitignore : just edit the file (with a text editor).

[anycommand] >> .gitignore just adds the output of [anycommand] at the end of the file ;
you should be able to spot the section with all the files listed by :

git status --porcelain | grep '^??' | cut -c4-

and just delete that section.


You should probably modify your .gitignore file anyway, it is not very conventional to ignore a long list of specific files.

  • if you really want to ignore every untracked file (current and future), set your .gitignore to :

    # ignore everything
    *
    

    you can still add new files using git add -f

  • if you want to ignore specific folders, just name those folders :

    # ignore the "tmp/" and "build/" directories :
    tmp/
    build/
    

For an extensive documentation : see git help ignore

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • The first option doesn't really make a lot of sense if the OP wants to "revert" the command given. Editing `.gitignore` to remove the lines added is a reasonable plan though. – Caleb Jun 04 '19 at 07:40