5 Seeing What Has Changed

Your local repository tracks changes. Before you start committing just anything, you need to see what changes exist between your working tree and your repository and what changes are staged and ready to commit. git status is the tool for the job.

git status has several different outputs, depending on what’s in your working tree. The example on the next page is from one of my repositories, and it contains all three types of outputs: staged changes, changes to known files, and untracked files. Let’s go over them in reverse order of how they appear on the next page—the order of least important to most.

Starting at lines 14 and ending at 17, Git outputs the files and paths that it doesn’t know anything about—the files that you haven’t told Git about yet. This section has the header Untracked files before it starts, and if you turned on color output like we discussed in Task 2, Configuring Git, it displays the files and paths in red.

Next up are the files that Git knows about but that have changed. These are listed between lines 8 and 12 and are preceded by Changed but not updated. Like untracked files, these show up as red if you have colors configured.

Finally, the top section listed between lines 3 and 6 shows what files you would commit if you ran git commit right now. For more on committing, flip to Task 7, Committing Changes. Files in this section show up as green if you turned colors on and are preceded by Changes to be committed.

Depending on the state of your repository, the output from git status might contain any of those sections or none at all. It adapts itself as needed.

What To Do...
  • What the status of a new repository looks like.

    If you just created a repository using git init, this is what your repository looks like:

     
    prompt>​ git status
     
    # On branch master
     
    #
     
    # Initial commit
     
    #
     
    nothing to commit (create/copy files and use "git add" to track)
  • What git status looks like in a repository with changes.

    git status requires a repository with some changes in its working tree to see the various output. The following is the output of git status on my local Castanaut repository:

    Line 1 
    prompt>​ git status
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD <file>..." to unstage)
    #
    # modified: castanaut.gemspec
    #
    # Changed but not updated:
    # (use "git add <file>..." to update what will be committed)
    10 
    # (use "git checkout -- <file>..." to discard changes in ...
    #
    # modified: README.txt
    #
    # Untracked files:
    15 
    # (use "git add <file>..." to include in what will be ...
    #
    # pkg/
  • What git status looks like with no changes.
     
    prompt>​ git status
     
    # On branch master
     
    nothing to commit (working directory clean)

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.254