Committing Changes to a Repository

Learn how to commit changes to a repository.

The git commit command#

The git commit command tells Git to take a snapshot of all added content at this point.

1   git commit -m "Some message"
2   git log
Terminal 1
Terminal

Click to Connect...

Now that git is aware of the mycode.py file, you can make a change to it and see how the local change looks by using git diff.

The git diff command#

3   vim mycode.py
4   git diff

After typing the vim command, you will be taken to a text editor on the terminal. Vim has two modes: a command mode and an edit mode. By default, you will be taken into the command mode. To enter into the edit mode, press the key i. To exit the edit mode and enter into the command mode, press the escape key. To save your changes, close the editor, and go back to the terminal. Type :wq in the command mode, and press enter.

Terminal 1
Terminal

Click to Connect...

Again, you can see what’s going on by looking at the status.

Simultaneous add and commit#

You can commit changes to files and add at the same time by doing git commit -a:

5   git commit -a -m "Another message"
6   git status

Alternatively, you can use git commit -am "Another message".

Checking history#

The git log command now shows the history of the file:

7   git log
Add Files to a Repository
Challenge: Git Basics
Mark as Completed
Report an Issue