Skip to Content
Git Pocket Guide
book

Git Pocket Guide

by Richard E. Silverman
July 2013
Beginner
231 pages
4h 23m
English
O'Reilly Media, Inc.
Content preview from Git Pocket Guide

Chapter 3. Making Commits

This chapter explains how to make changes to your repository content: add, edit, and remove files; manipulate the index; and commit changes.

Changing the Index

When you run git commit, without arguments or options, Git adds the contents of the index as a new commit on the current branch. So before committing, you add to the index those changes you want to commit. This can skip some changes you’ve made to your working files, if you’re not ready to commit those yet.

git commit <filename>

Giving a specific filename to git commit works differently: it ignores the index, and commits just the changes to that file.

Adding a New File

$ git add filename

This is suitably mnemonic, but note the next command.

Adding the Changes to an Existing File

$ git add filename

Yes, this is the same command. In both cases, Git adds the current working file contents to the object database as a new blob-type object (assuming it’s not already there), and notes the change in the index. If the file is new, then this will be a new index entry; if not, just an updated one pointing to the new object (or with changed attributes, such as permissions)—but it’s essentially the same operation to Git. A file is “new” if its pathname is not in the index, usually meaning it was not part of the last commit; this is what causes git status to note a file as “untracked” prior to your adding it (files in the index are called “tracked,” and they are the ones Git cares about, generally speaking).

The filename ...

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

Git: Mastering Version Control

Git: Mastering Version Control

Ferdinando Santacroce, Aske Olsson, Rasmus Voss, Jakub Narębski
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781449327507Errata Page