YouTip LogoYouTip

Git Commit

# git commit Command [![Image 3: Git Basic Operations](#)Git Basic Operations](#) * * * In the previous chapter, we used the git add command to write content to the staging area. The git commit command adds the content from the staging area to the local repository. Commit the staging area to the local repository: git commit -m can be some notes. Commit the specified files in the staging area to the repository: $ git commit ... -m The **-a** parameter allows you to skip the git add command after modifying files and commit directly $ git commit -a ### Setting User Information for Commits Before starting, we need to set up the user information for commits, including username and email: $ git config --global user.name 'tutorial' $ git config --global user.email test@ If you remove the --global parameter, it will only apply to the current repository. ### Committing Changes Now we can add all changes to hello.php from the staging area to the local repository. In the following example, we use the -m option to provide a commit message on the command line. $ git add hello.php $ git status -s A README A hello.php $ git commit -m 'First version commit'[master (root-commit) d32cf1f] First version commit 2 files changed, 4 insertions(+) create mode 100644 README create mode 100644 hello.php Now we have recorded the snapshot. If we run git status again: $ git status # On branch master nothing to commit (working directory clean) The output above shows that after our last commit, we haven't made any changes - it's a "working directory clean". If you don't set the -m option, Git will try to open an editor for you to fill in the commit message. If Git can't find the relevant information in your configuration, it will open vim by default. The screen will look like this: # Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:# (use "git reset HEAD ..." to unstage)## modified: hello.php#~~".git/COMMIT_EDITMSG" 9L, 257C If you find the git add staging process too cumbersome, Git also allows you to skip this step with the -a option. The command format is as follows: git commit -a First, let's modify the hello.php file to the following content: Then execute the following command: $ git commit -am 'Modify hello.php file' Modify hello.php file 1 file changed, 1 insertion(+) * * Git Basic Operations](#)
← Git RmGit Status β†’