There is a project with a tree-like folder structure, served by git. I am in the console at the top level of the project and I have several files that have been modified in subfolders. I see these modified files with the git status command, for example:

Changed files

There may be many similar files and I want to add them using wildcards. For example, add all csv files with the git add *.csv command, and all txt files with the git add *.txt command. I run these two commands, but as a result I see that only *.csv files were added to the index:

Only one added

Why not add files with the extension txt ?

  • one
    text information is better to attach as text: a) easier to read; b) can be copied; c) the search works. You can correct the question text by clicking below to edit the question text - aleksandr barakin
  • one
    @alexanderbarakin thanks for the advice, Alexander. Do not forget to begin sentences with a capital letter :) - αλεχολυτ
  • Thanks for the tips! do not forget about the convenience of readers, please. - aleksandr barakin
  • one
    @alexanderbarakin convenience does not suffer. All the necessary information is already in the text. Pictures are shown to show the differences between added and non-added files. - αλεχολυτ

1 answer 1

The problem may be that in folders whose level is higher than the folder of the problem file (for example, in the root, or in /one/ ), there are files that match the pattern, i.e. in this case, files with the txt extension. Thus, git add *.txt finds this file from a root or another level higher than desired (however, it is not changed and is not reflected in the results of the git status command) and stops looking for files in folders with more nesting.

Thus, in order to guarantee the addition of files from subfolders, you will have to specify the full path to these folders. But in some cases a combination of the form */*.txt can be useful, which will find files in nested folders (limited to the level of nesting where the first files matching the pattern will be found).

In this case, after the git add */*.txt command, the problem file will be added:

File added