Chuck's Academy

Git and GitHub

Making Commits and Tracking Changes

In this module, we will learn how to make commits and how to track changes in your files using Git. Commits are the cornerstone of version control because they allow us to save specific states of our project and revert to them if necessary.

Staging Area and Commits

Working in the Working Directory

The Working Directory is where you make and save changes to the project files.

Staging Area

The Staging Area is a "waiting area" where you put the changes you want to include in the next commit.

Local Repository

The Local Repository contains all the commits you have made on your local machine.

Making Commits

Step 1: Make changes to your files

Make changes to any file in your project. For example, modify the README.md file.

Step 2: Add changes to the staging area

To include all changes in the staging area, use the git add command:

bash

This command adds all changes (new files, modifications, and deletions) to the staging area.

To add a specific file:

bash

Step 3: Make a commit

Save your changes to the local repository with a descriptive message explaining what changes you made:

bash

Tracking Changes

View the status of the repository

The git status command shows the status of your working directory and staging area. It is useful for seeing which changes are pending:

bash

View the commit history

The git log command shows the commit history in your repository:

bash

For a more compact view:

bash

View differences between commits

The git diff command shows the differences between the content of the working directory and the content of the staging area or the last commit:

bash

To see specific differences:

bash

Practical Case

  1. Create a new file:

    bash
  2. Add the file to the staging area:

    bash
  3. Make the first commit:

    bash
  4. Modify the file: Open file.txt and change its content to "Updated content".

  5. View untracked changes:

    bash
  6. View differences:

    bash
  7. Add changes to the staging area:

    bash
  8. Make a new commit:

    bash
  9. View commit history:

    bash

Undo Changes

Remove files from the staging area

To remove a file from the staging area and return it to the working directory:

bash

Undo changes in the working directory

To undo changes in a modified file (and return it to its state from the last commit):

bash

Change the message of the last commit

If you made a mistake in the message of the last commit, you can modify it with:

bash

With these tools and commands, you can manage changes in your project with precision and safety. In the next module, we will delve into branching management.


Ask me anything