| id | commit-changes | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| title | Commit Changes | ||||||||||
| sidebar_label | Commit Changes | ||||||||||
| sidebar_position | 7 | ||||||||||
| description | Learn how to commit changes to a Git repository using Git. Commit your changes, add a commit message, and keep track of your project history with Git commits. | ||||||||||
| tags |
|
||||||||||
| keywords |
|
To save your changes to a Git repository, you need to commit them. Committing changes creates a snapshot of your project at a specific point in time, allowing you to track the history of your project and collaborate with others.
To commit changes to a Git repository, follow these steps:
-
Open your terminal or command prompt on your local machine. Navigate to the directory of your Git repository using the
cdcommand.cd path/to/repository -
Check the status of your repository to see which files have changed. Use the
git statuscommand to view the changes that are not yet staged for commit.git status
The
git statuscommand will show you the files that have been modified, added, or deleted since the last commit. -
Stage the changes you want to commit using the
git addcommand. This command adds the changes to the staging area, preparing them for the next commit.git add filename
:::tip Note: Replace
filenamewith the name of the file you want to stage. You can also usegit add .to stage all changes in the repository. ::: -
Commit the changes using the
git commitcommand. This command creates a new commit with the changes you staged in the previous step.git commit -m "Add new feature to the project":::tip Note: Replace
"Add new feature to the project"with a meaningful commit message that describes the changes you made in this commit. :::
-
Verify the commit by checking the commit history of your repository. Use the
git logcommand to view the commit history, including the commit message, author, date, and commit hash.git log
The
git logcommand will display a list of commits in reverse chronological order, showing the most recent commits first. -
Congratulations! You have successfully committed changes to your Git repository. Your project history is now updated with the new commit, and you can continue working on your project with confidence.