GIT – How To Commit Your Changes ?


How To Commit Your Changes

Table Of Contents:

  1. What Is GIT Commit?
  2. How To Commit Your Changes.
  3. Examples Of Committing Your Changes.

(1) What Is GIT Commit ?

  • When you are confirmed that whatever the changes you made are correct, it’s time for you to commit the changes to the ‘git’ repository.
  • GIT Commit will ensure that, whatever changes you have made to the file system, will be persisted by the GIT.
  • If you did some mistake in future, you can always roll back to the previous commits.

(2) How To Commit Your Changes ?

Method-1

git commit

Note:

  • A simple commit command will commit the changes and generate a commit-id.
  • It will take the files from the staging area.
  • The commit command without any argument will open the default text editor and ask for the commit message.
  • It asks you to enter some commit message describing the changes made.
  • To enter the message press ‘Esc’  and after that ‘I‘ for insert mode.
  • Now press ‘Esc’ and after that ‘:wq’ and press enter.
  • It will save the changes and exit from the editor. 
  • Now your changes have been committed.
  • And it will generate a unique commit-id.
  • If you check the status you can see, On the branch master, nothing to commit, working tree is clean.

Method-2

git commit -m

Note:

  • The -m option of the commit command lets you write the commit message on the command line.
  • This command will not prompt the text editor

Note:

  • Here I have added a comment “My Second Commit”.

Note:

  • Here you can see that files are committed successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *