Add all the latest changes to the commit in git

Asked

Viewed 14,272 times

10

Whenever I make several changes to files in Git, I go out by adding the changes one-by-one through the git add. It’s a bit of a boring process, I wonder if you have a command to add all the "not staged" changes at once.

  • Have you ever thought that there is a reason why you have to add all files manually?

5 answers

10


I usually use the command:

git add .

inserir a descrição da imagem aqui

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

9

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

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

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

Selecting one of the above options, the interactive mode will open for you more or less 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 those files that are listed above in Stage.

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

You can run several commands at the same prompt too, 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 command git add - A works but it is not recommended because it adds forcibly, all files that have not been versioned, this isn’t always good because sometimes you want to do commits separately to better contextualize your progress and also you may end up adding some unwanted file that wasn’t in the .gitignore before.

UPDATE

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

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

  • git add -p: Adds chunks of code that have been modified, also works only with files already added to git and is most recommended to use, as you can better contextualize what you’re updating.

I hope it helped.

  • 1

    good answer, never tried to use git interactively ...

7

You can use:

git add -A

5

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 causing all files to be picked up by er.

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

4

If they are files NEW, there’s no escape from git add -A or git add ., however, if there are changes in files EXISTING:

git commit -am "Sua Mensagem"

Already add and send a message to your branch

Browser other questions tagged

You are not signed in. Login or sign up in order to post.