EN VI

hidden files are also added with command " git add . "?

2024-03-15 00:30:05
How to hidden files are also added with command " git add . "

So in my local repository there are some hidden files (including .gitignore file) and some unhidden files and folders.

I used the command git add . and then I run command git status . here all files are being under "changes to be committed" part including hidden files. Please help I am unable to understand how to avoid adding hidden files in git. Is there a command to not include hidden files?

FYI: I am using git on the command line

Solution:

Generally speaking don't use git add . as an everyday command. Especially if it's not what you want. And if you are adding a massive load of files, just follow it with a git reset <file to not be added> before your commit.

The only files git won't add when are the .git folder becuase it knows that is its meta data, and anything not already committed that is listed in a committed .gitignore file.

There is no such thing to git as a "hidden file". Technically there is no such thing in Windows, OSX or Linux, there are files that are not normally displayed in UI windows, or by ls on the command line, but they are not "hidden" they just match a name pattern that says to not normally display. git doesn't care about any of that and it shouldn't.

And no I don't remember what happens if you have already committed a file and then make it git ignored.

In general I don't use git add . I'm using git add -u for all tracked files with changes to be picked up and then using git reset on the ones I didn't want added, or git add -p (optionally with a file name) for interactive patch adding, or git add prefix* to get a group of files. I only ever generally use git add . for a first commit and then I will trim things out of that with git reset before committing. I'm also usually checking status before I even add or commit.

Blindly using git add . is a great way to inadvertantly commit test files, password files, diffs, and all sorts of other things that you don't want into the repository.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login