📜  git add only c files - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:41:24.968000             🧑  作者: Mango

Git Add Only C Files - Shell/Bash

When working on a project, you may use Git to manage your changes and collaborate with others. Git is an incredibly versatile tool, but it can also be very specific when it comes to the files it tracks. For example, you may want to add only C files to your Git repository.

To do this, you can use the git add command with the --glob option. The --glob option allows you to use a pattern to specify which files to add, based on their filename or extension.

Here's an example of how to add only C files to Git using a Bash script:

#!/bin/bash

# Find all C files in the current directory and its subdirectories
c_files=$(find . -name "*.c")

# Add each C file to Git
for file in $c_files
do
    git add "$file"
done

In this example, the script uses the find command to locate all files with a .c extension in the current directory and its subdirectories. It then loops through each file found, using git add to add it to the Git repository.

You can also use the --no-warn-embedded-repo option to prevent Git from adding any sub-repositories that may be embedded in your C files.

#!/bin/bash

# Find all C files in the current directory and its subdirectories
c_files=$(find . -name "*.c")

# Add each C file to Git, ignoring any embedded repositories
for file in $c_files
do
    git add --no-warn-embedded-repo "$file"
done

This Bash script will only add C files to your Git repository while ignoring any embedded repositories found within them.

Using git add with the --glob option and a Bash script provides an efficient and effective way to manage your C files and Git repository.