Git is a distributed version control system that helps you manage your project's history, collaborate with others, and keep track of changes over time. A fundamental concept in Git is the "commit."
A commit is like a snapshot of your project at a specific point in time. It captures the changes you've made to your files. Each commit has a unique identifier (hash) and a commit message that describes the changes you've made. Commits help you understand the history of your project and enable you to switch between different versions.
In this exercise, you will practice creating commits in an existing Git repository. The goal is to create three files, not including this README, and make a commit for each file. Follow these steps:
-
Open your terminal or command prompt.
-
Clone the Git repository to your local machine:
git clone <repository_url>
cd git-basics-exercise- Create a new text file (e.g.,
file1.txt) with some content. You can use any text editor or command line tools to create the file. - Check the status of your repository to see which files are not yet committed:
git status- Add the new file to the staging area:
git add file1.txt- Create your first commit:
git commit -m "Add file1.txt"- Repeat the process to create two more files (
file2.txt,file3.txt). For each file, add and commit it with meaningful commit messages. - After creating and committing all four files, use the following command to view the commit history:
git logYou'll see a list of commits, including their commit hashes, messages, authors, and dates.
Congratulations! You've completed the exercise and practiced creating commits in a Git repository. Commits are an essential part of Git and help you track your project's history. You can continue exploring Git by branching, merging, and collaborating with others. Happy coding!