Is there a way to just install one file type extension from a folder?

I am learning to control my source code with git, and I'm still really a noob in this part. In any case, the question speaks for itself, I have a folder with a lot of materials, and I would just like to write the extension files ".c". Is there a command to perform this trick or do I need to add each file name manually? I did research even here on stackoverflow, and I didn’t find anything on it, maybe I was looking for the wrong concept, so any help would be appreciated.

early

+8
source share
3 answers

If you want to add all the files with a specific file extension, all you have to do is specify it while you go to generate the files with a wildcard.

git add *.c

Here .c can be any extension you want.

+12
source

For me, just git add *.c did not work. I encountered a fatal error:

 git add *.php The following paths are ignored by one of your .gitignore files: wp-config.php Use -f if you really want to add them. fatal: no files added 

So, in this option, git tried to add ignored files.

But this option:

 git add \*.php 

worked flawlessly. By the way, you can do git diff in the same way:

 git diff -- \*.php 
+10
source

@Ryan's answer will work if you only care about the files directly in the folder, but don't care about adding files with the specified extension from subfolders.

If you want to add all files with the same extension to the base folder and all subfolders recursively, you can use:

 git add [path]/\*.java 

add Java files from subdirectories, or

 git add ./\*.java 

for the current directory.

(From git add documentation )

0
source

Source: https://habr.com/ru/post/1205986/


All Articles