Difference from: "git commit -am" and "-m"

Asked

Viewed 4,481 times

6

What would be the difference between typing: git commit -m "Teste" and git commit -am "Teste"?

I’m learning about Git and would like to know how to differentiate it.

3 answers

13


The command:

git commit -m "Teste"

Commit only the modified and added files in the area of Stage (Changes to be committed) Git. That is, it’s just the files you added using a command like this:

git add nome_arquivo.txt

Or this:

git add .

Already the command:

git commit -am "Teste"

Do two things: add all modified files in the Stage and then commit them. In terms of the command, it’s the same that you do these two commands below:

git add .               # adiciona todos os arquivos modificados no stage
git commit -m "Teste"   # faz o commit dos arquivos modificados
  • 2

    In general, on the staging area

  • So I don’t need to use the git add ... and I can only use the -am? This will facilitate my process.

  • 1

    @Henrique Depende. If you have any files that you don’t want to go to the next commit, you better do add [arquivos que quero] and commit (without the -a) separately. But if you want everything to be committed, use -a

  • Yes, yes, thank you very much.

4

Instead of you needing to make one git add <meu arquivo> (which adds the file to carry out your commit) and then do a git commit -m <minha mensagem de commit> (commits its change by assigning a message to it), the git commit -am <minha mensagem de commit> already makes these two steps at once.

4

The git commit -m sets only the commit of the modifications that are previously added to your tree, combining this with the option -m, waiting for a message to bring your commit to life.

Using the -a you beyond the commit and message, add all the files that are already trackeados by git, beware, as -a option does not add files created at the moment, only those that form modified or deleted. Thus, you can join the -a with the -m resulting in -am saving you the time of git add <diretório(s) ou arquivo(s)>

Browser other questions tagged

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