GarouDan GarouDan - 4 months ago 25
Git Question

Git. How to add all files that are not those returning error?

Using linux, I would like to do something like in the script below using git:

cd /
sudo git init .
sudo git add -A
sudo git commit -m "Genesis."

I would like to do this to see which files are changed in the filesystem when I install some software and for another purposes of mine.

But when I try
sudo git add -A
I receive some error messages like:

error: readlink("proc/10/exe"): No such file or directory
error: unable to index file proc/10/exe
fatal: adding files failed

But this is OK, probably /proc files will not help me so much.
So I would simple add all files but ignoring the files that I receive errors.
I tried
sudo git add -A --ignore-errors
and a bigger output had come, unfortunately when running
git status
nothing happened.

So, how could I add all files that will not cause errors to achieve what I need?


After trying several things looks like I'd reached an answer:

sudo find * -type f | sudo xargs git add

This operation took a long time but worked. The truth is I ran sudo find {folder here} -type f | sudo xargs git add to each folder in /.

I was trying to do this on a vagrant VM (ubuntu/trusty64) and after the operation the .git folder was with about 600MB.

Then I searched for a command to get all files that was not tracked and add them to .gitignore.

So I used this:

sudo git status -s | grep -e "^\?\?" | grep -v ".gitignore" | cut -c 4- >> .gitignore

Unfortunately 7 pem "files" was not put in the .gitignore:


I tried put them manually but didn't work. But I think, for inspection purposes, this will not be a problem.

If is there a way to put this files in .gitignore I would like to know.

Thanks for help.