The difference between git commit -m and git commit -am

Literalally, git commit -m is used to submit the file in the staging area; git commit -am is used to submit the tracked file.

To understand the difference, first understand the git file state change cycle, as shown below

git

All files under the working directory are nothing more than these two states: tracked or not tracked. Traced files are files that have been included in version control management. They have their records in the last snapshot. After a period of work, their status may be unupdated, modified, or placed in the staging area.

The following is an example

When a new file such as 'a.txt' is added to the project folder, the file is in an untracked untracked state. Files that are not tracked are unsubmitted

Next,Use git add a.txt to make it tracked

At this time, if you use git commit -m 'add a.txt', you can submit it successfully.

But what is the difference between git commit -m and git commit -am? After the modification of the a.txt file

Next, add the content 'a' to a.txt

The file a.txt is in tracked but not in a staging state. At this time, if you use git commit -m to submit the latest version of a.txt, the old version a.txt that was originally empty is submitted.

To submit a new version of a.txt, a.txt with the content 'a', you need to use git add a.txt to put the new version of a.txt in the staged staging area before you can use git commit -m submit

If you use git commit -am, you can omit the git add a.txt step, because git commit -am can submit the tracked file, and a.txt has been tracked at the beginning.

In summary, the key to using these two commands is the git add command.

The git add command is a versatile command. The effect of this command is different depending on the state of the target file: you can use it to start tracking new files, or put the tracked files in the staging area, and also use them when merging. Conflicting files are marked as resolved, etc.

We need to use the git add command to keep track of new files, but if you use git commit -am you can omit the ability to put traced files into the staging area using the git add command.

Reprinted at: https://www.cnblogs.com/FineDay/p/9191144.html

Intelligent Recommendation

The difference and relationship between git add and git commit in Git

The difference and relationship between git add and git commit in Git Use the git add command to write the contents of the snapshot you want to the cache. Use the git commit command to add the content...

git commit -m "comment" error

Error content:Author identity unknown *** Please tell me who you are. Run git config --global user.email “[email protected]” git config --global user.name “Your Name” to set your...

The first git commit cannot use git commit -a -m

I created a new project today, localgit initAfter that, I want to submit the code to the remote warehouse, so I use it firstgit commit -a -m "Commit information", And found the following inf...

git commit - branch commit

background based onPrevious: git checkout-new branchBackground, continue to understand the command used git commit Official website grammar introduction NAME git-commit - Record changes to the reposit...

Git--commit commit compression

Git-commit commit compression The first: through the editor IDE (pro-test) I use idea, and commit compression through idea. first step: Select the current branch, and then view the version control (Ve...

More Recommendation

【Git】commit commit code

catch Katalon configures git and git project creation_Spring Spinach Blog - CSDN Blog The correct steps and commands for submitting code for it? When programmers develop code, they often use git, a co...

git commit

Usually when we submit git   These three big steps, in fact, you only need two orders is enough, unless there are new files to be added....

git commit -a

I encountered such a problem when submitting git today. I rm dropped many files in the project. When I wanted to commit, I found that these deleted files were not staged. It would be too boring to go ...

git commit

Create a branch at a commit node git checkout -b feature20171102 45efd508d3b689d947d8d3393e9b39faa6b4c17c Cancel the commit after a certain node, but the code remains current git reset –soft 30a...

After git commit -am, revoke and keep the changes

surroundings Operating system: win7 git: 2.9 Scenes Sometimes we are doingcommitAfter that, regret it! The specific points are: My company’s process should be that the code is first submitted to...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top