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
Diego Feb 28 '13 at 17:36 2013-02-28 17:36
source share