i2tutorials

Git – Local repository

Git Local Repository

 

As soon as a file is created, it will be added to the local repository by adding and committing it.

Git Commit :

Git commit command :

The commit command commits the changes and generates a commit-id. The commit command without an argument will open the default text editor and ask for a commit message. Here’s ours:

$ git commit  

It’ll open a default editor and ask for a commit message. We’ve changed newfile1.txt and want to commit it.

Here’s what it looks like:

Git Local Repository

When we run the command, a default text editor will pop up and ask for a commit message.

Then press Esc after that ‘i’ for insert mode. Type whatever you want. Press Esc after that ‘:wq!‘ to save and exit from the editor.

Check the commit by running git log. Here’s what we get:

Log option displays commit-id, author details, date and time, and commit message in the above output.

Git commit -a

You can specify some commits by using the -a option. This option only considers files that have already been added to Git. It will not commit newly created files. Consider the following scenario:

The staged file newfile3 has been updated and a new file newfile4.txt has been created. Run the commit command and check the status of the repository:

$ git commit -a  

Consider the output:

This command will prompt our default text editor for a commit message. Type the commit message and save and exit the editor. Only the files that are already added will be committed. The files that haven’t been staged won’t be committed. Consider the output below:

According to the above output, newfile4.txt has not been committed.

Git commit -m :

When you use the -m option of commit, you can write the commit message directly on the command line. This will not prompt the text editor.

$ git commit -m "Commit message."  

With the above command, a commit will be made with the given commit message. Below is the output:

A newfile4.txt file is committed to our repository with a commit message in the output above.

 

Exit mobile version