HOWTO · Git

Agregar archivos en Git

Este artículo demuestra los diferentes métodos para agregar archivos a su repositorio en Git.

Este artículo discutirá los diferentes métodos para agregar archivos a nuestro repositorio en Git.

Agregue todos los archivos usando el comando git add en Git

Podemos agregar todos los archivos sin excepción con el comando git add como se muestra a continuación.

git add -A

El argumento -A le indica a Git que agregue todos los archivos presentes en su índice. Git organizará los archivos sin seguimiento, modificados y eliminados para el commit.

Alternativamente, puede ejecutar el comando git add, que le indica a Git que organice los archivos en su directorio actual.

Ejemplo:

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
    (use "git add/rm <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
        deleted:    README.md
        modified:   Sample.txt
Untracked files:
    (use "git add <file>..." to include in what will be committed)
        Sample.txt.bak
        Tutorial.txt
no changes added to commit (use "git add" and/or "git commit -a")

En el ejemplo anterior, tenemos un índice con los siguientes archivos.

  1. Un archivo Sample.tx modificado.
  2. Un archivo README.md eliminado.
  3. Y dos archivos sin seguimiento.

Ejecutamos el comando git add -A para preparar todos los archivos para el commit, como se muestra a continuación.

git add -A

Ejecutemos el comando git status para verificar si Git preparó nuestros archivos.

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
        deleted:    README.md
        modified:   Sample.txt
        new file:   Sample.txt.bak
        new file:   Tutorial.txt

Nuestros archivos están listos para confirmar.

Agregar archivos por extensión en Git

A veces, es posible que necesite formatos de archivo específicos de la etapa. Por ejemplo, un archivo .js o un archivo .txt.

Usamos el comando git add para agregar un comodín y la extensión del archivo. A continuación se muestra un ejemplo.

Tenemos un archivo JavaScript que queremos preparar para el commit en nuestro directorio.

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
        deleted:    README.md
        modified:   Sample.txt
        new file:   Sample.txt.bak
        new file:   Tutorial.txt
Untracked files:
    (use "git add <file>..." to include in what will be committed)
        New Text Document.txt
        New.js

Podemos ejecutar el comando git add en el siguiente contexto.

$ git add *.js

Ejecutemos el comando git status para verificar si Git preparó el archivo.

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
        new file:   New.js
        deleted:    README.md
        modified:   Sample.txt
        new file:   Sample.txt.bak
        new file:   Tutorial.txt
Untracked files:
    (use "git add <file>..." to include in what will be committed)
        New Text Document.txt

Como puede ver, nuestro archivo New.js se preparó para el commit.

Agregar archivos eliminados y modificados solo en Git

Usamos el comando git add con el argumento -u para indicarle a Git que agregue solo los archivos eliminados y modificados para el commit.

Ejemplo:

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
        new file:   New.js
        deleted:    README.md
        modified:   Sample.txt
        new file:   Sample.txt.bak
        new file:   Tutorial.txt
Changes not staged for commit:
    (use "git add/rm <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
        modified:   Sample.txt
        deleted:    Sample.txt.bak

Ejecutamos el siguiente comando si queremos organizar nuestros dos archivos.

$ Git add -u

Ejecutaremos el comando git status para verificar si Git preparó los dos archivos.

pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
        new file:   New.js
        deleted:    README.md
        modified:   Sample.txt
        new file:   Tutorial.txt
Untracked files:
    (use "git add <file>..." to include in what will be committed)
        New Text Document.txt

Hemos agregado los archivos eliminados y modificados para el commit.