git commit -m 与 git commit -am 的区别
为情所困
为情所困 2017-05-02 09:36:32
0
3
982

麻烦解答下 git commit -m 与 git commit -am 的区别

为情所困
为情所困

reply all (3)
迷茫

When the modification has been approvedgit add 将其添加到stage,可以通过git commit -m ""为这所有已经进入stage的改变添加一个commit信息。什么是在stage? See below

If your file has been submitted before, but this time the changes have not been madestage, as follows:

You can directly usegit commit -am ""to add all modifications but notgit commit -am "",将所有修改,但未进stage的改动加入stage,并记录commit信息。(某种程度上相当于git addgit commit -m的组合技,前提是被改动文件已经是trackedto

, and record the commitinformation. (To some extent, it is equivalent to the combination of git addand git commit -m, provided that the modified file is already tracked)
    给我你的怀抱
    git commit -am "str" #等同于 git commit -a -m "str"

    Let’s run it

    man git commit

    To get the meaning of theaparameters, you will know the difference.

    OPTIONS
    -a, --all
    Tell the command to automatically stage files that have been modified and >deleted, but new files you have not told Git about are not affected.

    means

    Automatically put all currently modified and deleted files on the stack, but those you have not added will not be affected.

    Expand

    Usually when we submit git

    git add . git commit -m "some str" git push

    These three big steps, but in fact, you only need two commands, unless there are new files to be added.

    git commit -am "some str" git push
      伊谢尔伦

      Literally explained, git commit -m is used to submit files in the staging area; git commit -am is used to submit tracked files

      To understand their differences, you must first understand the file status change cycle of git, as shown in the figure below

      All files under the working directory are in these two states: tracked or untracked. Tracked files refer to files that have been included in version control management. They are recorded in the last snapshot. After working for a period of time, their status may be not updated, 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 state. Files in untracked status cannot be submitted

      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 smoothly

      But what is the difference between git commit -m and git commit -am? It depends on the processing after modifying the a.txt file

      Next, add content 'a' to a.txt

      The file a.txt is tracked but not staged. At this time, if you use git commit -m, you cannot submit the latest version of a.txt. What is submitted is only the old version of a.txt with empty content at the beginning

      To submit a new version of a.txt, that is, a.txt with the content 'a', you need to use git add a.txt to put the new version of a.txt into the staged temporary storage area, and then use git commit -m Make a submission

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

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

      The git add command is a multi-functional command. Depending on the status of the target file, the effect of this command is also different: you can use it to start tracking new files, or to put tracked files into the temporary storage area, and it can also be used to merge files. Conflicted files are marked as resolved status etc.

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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!