Making Changes and Committing
In this section, we will explore how to make changes to files in your local repository using GitHub Desktop and how to commit those changes effectively. Understanding how to manage changes and make commits is crucial in version control, as it helps in maintaining a clear history of what has been modified, when, and by whom.
Understanding Changes in Git
In Git, every change you make to your files is tracked. Whenever you modify a file, Git recognizes it as a 'change'. These changes can be new files, modified files, or deleted files.
Types of Changes
1. Untracked: Files that are new and not yet added to the Git repository. 2. Modified: Files that have been changed after the last commit. 3. Deleted: Files that have been removed from the working directory.Making Changes in GitHub Desktop
Step 1: Modify Your Files
To start making changes, open your project directory and edit the files you want using any text editor or IDE.Practical Example: Suppose you have a file named index.html in your project. You can add a new tag or modify existing text within that file.
Step 2: View Changes in GitHub Desktop
Once you have made your changes, open GitHub Desktop. You will see a list of changed files in the Changes tab.Step 3: Reviewing Changes
Clicking on a file name will show you a diff view, which highlights the lines that have changed. This is useful for reviewing your modifications before committing.Code Example:
`html
Welcome to My Website
This is a sample project.
`Committing Changes
Once you are satisfied with your changes, the next step is to commit them. A commit is like a snapshot of your repository at a point in time.
Step 1: Write a Commit Message
Before you commit, you must write a clear and concise commit message. This message should explain what changes you made and why they are necessary.Good Commit Message Example: Add header section to index.html
Step 2: Commit Your Changes
To commit, type your message in the Summary box and click the Commit to main button. This action will save your changes into the local repository.Best Practices for Commit Messages
- Use the imperative mood (e.g., “Add”, “Fix”, “Update”) - Keep it short yet descriptive - Reference issues if applicable (e.g., “Fixes #42”)Summary
Making changes and committing them in GitHub Desktop is essential for effective version control. By tracking your modifications and using meaningful commit messages, you can maintain a clean project history that is easy to navigate.
Quiz
Question:
Why is it important to write clear and concise commit messages when making changes in Git?- Option A: It helps you remember what you did. - Option B: It allows others to understand the purpose of the changes. - Option C: It is required by GitHub to make a commit. - Option D: It reduces the size of the repository.