Skip to main content

GitKit (2nd ed.): Learn git and GitHub in Context

Section 3.5 Staging Changes

As you saw in the previous section, you now have modifications to your local files that have not been staged. The process of staging changes (i.e. adding the files to the stage) is illustrated in Figure 3.5.1. Recall from Figure 3.4.1 that the blue dot in Local Files represents the changes you made. In Figure 3.5.1, those changes are staged and will be made into a commit that is added to your feature branch in the next section.
Staging Changes.
Figure 3.5.1. Staging changes.

Exercises

The exercises in this section will walk you through staging the changes you made to your Local Files.
The git stage <file> command adds the indicated file to the stage, preparing it to become a part of the next commit.

1.

Write a git stage <file> command to stage the file that you edited.
Enter the command you wrote below.
Hint.
Check your issue again to see which file you should have edited.

2.

Now run the git status command again. Paste the output of the git status command below.

3.

    Compare your output in Exercise 3.5.2 to the output in Task 3.4.4.a.
    How many files are not staged?
  • 0
  • Correct! After issuing the git stage command the file will be staged.
  • 1
  • Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
  • 2
  • Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
  • Cannot be determined from the output provided by the git status command.
  • The git status command will show you all unstaged and staged files.
Hint.
Staged means a file has been modified and will be added to the commit.

4.

    How many files are listed as ready to be committed?
  • 0
  • If you issued the git stage command properly the file you changed should appear as ready to be committed.
  • 1
  • Correct! After issuing the git stage (or git add) command the file will be staged.
  • 2
  • Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
  • Cannot be determined from the output provided by the git status command.
  • The git status command will show you all unstaged and staged files.
Hint.
Staged means a file has been modified and will be added to the commit.

5.

    Run the git diff command again. What output is produced?
  • No output is produced.
  • Correct! There are no differences because your changes were staged.
  • It shows the file name that I changed.
  • If you are seeing the file name you changed it means either you made additional changes after the git stage command was done or your git stage command did not work properly.
  • It shows the code I added in green.
  • If you are seeing code changes it means either you made additional changes after the git stage command was done or your git stage command did not work properly.
  • It shows the code I deleted in red.
  • If you are seeing code changes it means either you made additional changes after the git stage command was done or your git stage command did not work properly.
Hint.
The git diff command will only show the changes that have yet to be staged.
The git diff --staged command will show you the differences between the staged changes and the most recent commit. Try this command now.
Note that git also has a git add command that is equivalent to git stage. So, you can add files to the stage using either git stage or git add. These activities will use git stage because it seems more descriptive of what is happening. However, you are likely to see git add used in other resources, so it is worth knowing that they are equivalent.
You have attempted 1 of 6 activities on this page.