Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this git's correct behavior for "git add" with subfolders?

Tags:

git

msysgit

When using "git add" with a file pattern it only adds recursively the untracked files, and ignores the changed ones unless they are in the current folder.

Example:

$ git status
# On branch master
# Changed but not updated:
#    (use "git add <file>..." to update what will be committed)
#    (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:    level1/test1.txt
#       modified:    level1/level2/test1.txt
#
# Untracked files:
#   (use "git add <file>..." to incldude in what will be committed)
# 
#       level1/test2.txt
#       level1/level2/test2.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add level1\*.txt
$ git status
# On branch master
# Changes to be committed:
#       new file:   level1/level2/test2.txt
#       new file:   level1/test2.txt
#
# Changed but not updated:
#       modified:   level1/level2/test1.txt
#       modified:   level1/test1.txt
#

After I execute git add level1\*.txt, the untracked (test2.txt) files are added, but not the modified (test1.txt) files. I've tried with the -u option, escaping and not escaping the asterisk, etc. but nothing seems to simply be able to add ALL files matching a pattern whether they are tracked or not.

Of course in this example I could just add all the files with -A, but keep in mind this is just for the purpose of this question, in reality there will be more files and I would not want to add them all, and the hierarchy is a few folders deeper. The only way for me to add the tracked files is referring to the directing or writing the whole pattern except for the file name like this: git add level1**.txt OR git add level1/level2/*.txt.

In the git add documentation: here it says that the file pattern is supposed to work recursively and doesn't say anything about tracked or untracked files and it even gives and example.

I'm using msysgit but I've tested this on Windows and Linux just in case.

I just want to know. Am I interpreting the documentation correctly (because I think based on the docs it should work) or is this how it is supposed to work? It just doesn't make sense to me.

like image 530
bluediapente Avatar asked Nov 10 '10 15:11

bluediapente


People also ask

How do I add all subfolders in git?

So, to recursively add all files or folders and also sub folders to the staging area of git, we can either call “git add -A” or “git add –all”, it will add all files in the project workspace to the staging area, irrespective of location from where this command is executing.

How do you add folders to git add?

To add a specific directory in git, you can use the git add command followed by the directory's name. Start by creating a new directory in the sample_repo. The command above will only add the specified and ignore other untracked files.

Which of the following is correct to add all files in repository?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”.


1 Answers

All right, there might as well be an answer on this question.

No, that doesn't seem to be the right behavior at all. git add <filepattern> should be equivalent to git add file1 file2..., where those are the files matched by the pattern - and that's not what happens here.

like image 76
Cascabel Avatar answered Sep 19 '22 04:09

Cascabel