Lab 6: Git Staging and Commiting

In this tutorial I will show you how to stage and commit changes. In the HelloWorld project we have three files ie hello.txt, another_hello.txt, more_hello.txt, all of which have been changed. The changes in hello.txt and another_hello.txt are logically related while changes in more_hello.txt are related to some other work flow. So hello.txt and another_hello.txt files will go as a single commit. Here’s how it can be done.

git add hello.txt
git add another_hello.txt
git commit -m "Changes for hello.txt and another_hello.txt"
git add more_hello.txt
git commit -m "Unrelated change to more_hello.txt"

By separating staging and committing, you have the ability to easily fine tune what goes into each commit. Here’s a screenshot of all commands being executed with their output.

Git Staging and Commiting

All posts in this series:
Lab 1: Setup Git on your Machine
Lab 2: Create a Git Repository from Scratch
Lab 3: Check the Status of the Repository
Lab 4: Making Changes to files in the Working Directory
Lab 5: Staging Changes in Git
Lab 6: Git Staging and Commiting

Other related posts:
Git Delete a Local or Remote Branch
How to Clone a Git Repository into a Specific Folder?
Change the URI for a Remote Git Repository
How to Merge a Local Git Branch with Master
How to Setup Aliases and Shortcuts for Git Commands
How to create a .gitignore file in Windows

This content has been helpful to you?

Thanks for contributing!

Yes No