As you work on your project, you'll make changes to your files. To keep a record of these changes and tell the story of your project's evolution, you use a process called 'committing'. A commit acts like a snapshot of your project at a specific point in time. It's a fundamental concept in version control that allows you to track progress, revert to previous versions if needed, and collaborate effectively with others.
Think of committing as saving a version of your work. Each commit has a unique identifier (a SHA-1 hash, which is a long string of characters) and, crucially, a commit message. This message is your opportunity to explain what changes you made and why. Good commit messages are concise yet informative, helping you and your collaborators understand the history of the project without having to dig through code.
Before you can commit, you need to tell Git which changes you want to include in the next commit. This is done by 'staging' your changes. Staging is like preparing a package for shipping – you select the items you want to send. Once staged, Git knows these are the files to be included in the commit.
git statusThe git status command is your best friend for understanding what's going on. It will show you which files have been modified, which are staged, and which are untracked.
To stage a specific file, you use the git add command. If you want to stage all modified files in the current directory and its subdirectories, you can use the -A flag.
git add <filename>
git add -AOnce your changes are staged, you can commit them with a descriptive message using the git commit command. The -m flag allows you to provide the commit message directly on the command line.
git commit -m "Add feature: User login functionality"Alternatively, if you run git commit without the -m flag, Git will open your default text editor, allowing you to write a more detailed commit message. This is often preferred for more complex changes.