Skip to Content
Version Control with Git, 2nd Edition
book

Version Control with Git, 2nd Edition

by Jon Loeliger, Matthew McCullough
August 2012
Intermediate to advanced
452 pages
12h 39m
English
O'Reilly Media, Inc.
Content preview from Version Control with Git, 2nd Edition

Chapter 5. File Management and the Index

When your project is under the care of a VCS, you edit in your working directory and commit your changes to your repository for safekeeping. Git works similarly but inserts another layer, the index, between the working directory and the repository to stage, or collect, alterations. When you manage your code with Git, you edit in your working directory, accumulate changes in your index, and commit whatever has amassed in the index as a single changeset.

You can think of Git’s index as a set of intended or prospective modifications. You add, remove, move, or repeatedly edit files right up to the culminating commit, which actualizes the accumulated changes in the repository. Most of the critical work actually precedes the commit step.

Tip

Remember, a commit is a two-step process: stage your changes and commit the changes. An alteration found in the working directory but not in the index isn’t staged and thus can’t be committed.

For convenience, Git allows you to combine the two steps when you add or change a file:

    $ git commit index.html

But if you move or remove a file, you don’t have that luxury. The two steps must then be separate:

    $ git rm index.html
    $ git commit

This chapter[9] explains how to manage the index and your corpus of files. It describes how to add and remove a file from your repository, how to rename a file, and how to catalog the state of the index. The finale of this chapter shows how to make Git ignore temporary and other irrelevant ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Version Control with Git

Version Control with Git

Jon Loeliger
Version Control with Git, 3rd Edition

Version Control with Git, 3rd Edition

Prem Kumar Ponuthorai, Jon Loeliger
Git for Programmers

Git for Programmers

Jesse Liberty

Publisher Resources

ISBN: 9781449345037Errata Page