Actions

EmSys

Git - Staging and Committing

From EdWiki

GitLab - Staging and Committing

  • A separate staging step in git is in line with the philosophy of getting out of the way until you need to deal with source control.
  • You can continue to make changes to your working directory, and then at the point you want to interact with source control, git allows you to record your changes in small commits that record exactly what you did.
  • For example, suppose you edited three files a.c, b.c, and c.c. Now you want to commit all the changes, but you want the changes in a.c and b.c to be a single commit, while the changes to c.c are not logically related to the first two files and should be a separate commit.
  • You could do the following:
git add a.c
git add b.c
git commit -m "Changes for a and b"
git add c.c
git commit -m "Unrelated change to c"

By separating staging and committing, you have the ability to easily fine tune what goes into each commit.