Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is git commit -am redundant, if I do git add before?

Tags:

git

Is it redundant to run git add . and then git commit -am "commit message"?

Can I just run git add . and then git commit -m "commit message" or, alternatively, just git commit -am "commit message"?

like image 378
Lee McAlilly Avatar asked Sep 02 '10 17:09

Lee McAlilly


People also ask

Do I need to git add before every commit?

As you're working, you change and save a file, or multiple files. Then, before you commit, you must git add . This step allows you to choose what you are going to commit.

Does git add or git commit first?

First, you edit your files in the working directory. When you're ready to save a copy of the current state of the project, you stage changes with git add . After you're happy with the staged snapshot, you commit it to the project history with git commit .

Is git add the same as git commit a?

Add and commit changesgit add : takes a modified file in your working directory and places the modified version in a staging area. git commit takes everything from the staging area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.

What happens if I commit without adding in git?

Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.


1 Answers

Git add + git commit -m will just commit those files you've added (new and previously tracked), but git commit -am will commit all changes on tracked files, but it doesn't add new files.

like image 116
Tuminoid Avatar answered Sep 28 '22 18:09

Tuminoid