How To Commit Your Changes
Table Of Contents:
- What Is GIT Commit?
- How To Commit Your Changes.
- 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.
![](https://www.praudyog.com/wp-content/uploads/2023/03/77-300x142.jpg)
(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.
![](https://www.praudyog.com/wp-content/uploads/2023/03/84-768x447.jpg)
![](https://www.praudyog.com/wp-content/uploads/2023/03/78-768x453.jpg)
- 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.
![](https://www.praudyog.com/wp-content/uploads/2023/03/80-768x447.png)
- Now press ‘Esc’ and after that ‘:wq’ and press enter.
- It will save the changes and exit from the editor.
![](https://www.praudyog.com/wp-content/uploads/2023/03/81-768x448.png)
- Now your changes have been committed.
- And it will generate a unique commit-id.
![](https://www.praudyog.com/wp-content/uploads/2023/03/82-768x447.png)
- If you check the status you can see, On the branch master, nothing to commit, working tree is clean.
![](https://www.praudyog.com/wp-content/uploads/2023/03/83.png)
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.
![](https://www.praudyog.com/wp-content/uploads/2023/03/85.png)
Note:
- Here I have added a comment “My Second Commit”.
![](https://www.praudyog.com/wp-content/uploads/2023/03/86.png)
Note:
- Here you can see that files are committed successfully.