Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when you run `git add .git` in a Git repository?

Tags:

git

git-add

While it seemed to do nothing, it gave no warning or error message. Any ideas?

like image 861
Andres Riofrio Avatar asked Jul 27 '11 05:07

Andres Riofrio


People also ask

What does git add do in github?

What Does Git Add Do? git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit.

What is git add and git commit?

git add : takes a modified file in your working directory and places the modified version in a staging area. git commit takes everything from the staging area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.

Does git add add new files?

git add -u looks at all the already tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.


1 Answers

Comment from Git source:

/*  * Read a directory tree. We currently ignore anything but  * directories, regular files and symlinks. That's because git  * doesn't handle them at all yet. Maybe that will change some  * day.  *  * Also, we ignore the name ".git" (even if it is not a directory).  * That likely will not change.  */ 

Experiment to see what happend if I create a file .git and try to add it: (on Windows I cannot create a file .git when there is already a .git folder. I also could have created a .git elsewhere in a sub directory, but wanted to try out --git-dir and --work-tree which I haven't used before. After all I am experimenting. This also allows me to show that I can add the git metadata folder as seen below)

git --git-dir="c:/test" init touch blah git --git-dir="c:/test" --work-tree="." add . git --git-dir="c:/test" --work-tree="." status ( shows blah added) touch .git git --git-dir="c:/test" --work-tree="." add .git ( no output as usual) git --git-dir="c:/test" --work-tree="." status ( only blah shown) 

So yeah, .git - be it directory or file, is ignored by git.

And if I do something like below:

git --git-dir="c:/test" --work-tree="c:/test" add c:/test 

all the meta files get added.

So again, it is only .git that is ignored not the git metadata folder (that you set via --git-dir) as far as I can see.

like image 187
manojlds Avatar answered Oct 12 '22 23:10

manojlds