Add all the latest commit changes to git

6

Whenever I make several changes to files in Git, I quit by adding the changes one-by-one through git add . It is a rather annoying process, I wonder if you have a command to add all the changes "not staged" at one time.

    
asked by anonymous 26.07.2016 / 18:51

5 answers

7

I usually use the command:

git add .

Note: As of version 2.0 of Git the command git add . is equivalent to git add -A . In versions 1.x, git add -A automatically adds all changes (new files, modified and deleted) while git add . adds only new / modified files to stage.

    
26.07.2016 / 20:32
6

You can use:

git add -A
    
26.07.2016 / 19:04
6

You can add multiple files in git through the interactive prompt git add -i

At the interactive prompt you have two commonly used options that are:

  • update ( 2 or u ): for you to choose which files you have previously added, you want to add them to the stage.
  • add untracked ( 4 or a ) for you to add files not yet included to the git versioning.

By selecting one of the options above, the interactive mode will open for you something like this:

      staged           unstaged path
1:    unchanged        +1/-1 folder/arquivo1.txt
2:    unchanged        +1/-1 folder/arquivo2.txt
3:    unchanged        +1/-1 folder/arquivo3.txt
4:    unchanged        +1/-1 folder/arquivo4.txt
5:    unchanged        +1/-1 folder/arquivo5.txt
6:    unchanged        +1/-1 folder/arquivo6.txt
7:    unchanged        +1/-1 folder/arquivo7.txt

You have several ways to add these files that are listed above in the stage.

  • To add one by one, enter the file number.
  • To add a range, type n-m (example: 2-4 adds files 2, 3, 4 and 5 at one time)
  • To add all, type *
  • To remove a file or range, type - before the number or range.

You can run several commands at the same prompt as well, examples:

# Adiciona ao stage todos arquivos, menos os numeros 4, 5 e 6
Update>> * -4-6 

# Adiciona ao stage todos arquivos menos o 5
Update>> 1-3 4 6-7

The git add - A command works but it is not recommended, because it adds forcefully, all files that have not been versioned, this is not always good because sometimes you want to do commits separately to better contextualize your progress and you may also end up adding some unwanted file that was not in .gitignore before.

UPDATE

Just two more commands to add changes that are very useful and frequently used.

  • git add -u : adds all modified files to the stage, only files that have already been added to git will be added.

  • git add -p : Adds bits of code that have been modified, it also works only with files already added to git and is the most recommended to use because you can better contextualize what you are updating.

    >

I hope you have helped.

    
26.07.2016 / 23:01
4

Using:

git add -A

and

git add --all 

you get the same result (actually the first and an abbreviation of the second).

Another way would be to use er :

git add *

But for this to work you need to be in the root repository by having all files get er .

In an extreme case if you want to make these commands even more abbreviated, you can try git aliases to abbreviate them.

    
26.07.2016 / 21:04
4

If they are NEW files, you can not escape git add -A or git add . , but if there are changes to EXISTING files:

git commit -am "Sua Mensagem"

Already add and give a message to your branch

    
26.07.2016 / 19:23