How to Record Changes in Git
How to Record Changes in Git 관련
Usually, when we work on our source code we work from a working dir. A working dir(ectrory) (or working tree) is any directory on our file system which has a repository associated with it. It contains the folders and files of our project, and also a directory called .git
that we will talk more about later.
After we make some changes, we want to record them in our repository. A repository (in short: repo) is a collection of commits, each of which is an archive of what the project’s working tree looked like at a past date, whether on our machine or someone else’s.
Unlike other, similar tools you may have used, git
does not commit changes from the working tree directly into the repository. Instead, changes are first registered in something called the index, or the staging area.
Both of these terms refer to the same thing, and they are used often in git
’s documentation. We will use these terms interchangeably throughout this post.
When we checkout
a branch, git
populates the index with all the file contents that were last checked out into our working directory and what they looked like when they were originally checked out. When we use git commit
, the commit is created based on the state of the index.
The use of the index allows us to carefully prepare each commit. For example, we may have two files with changes since our last commit in our working dir. We may only add one of them to the index (using git add
), and then use git commit
to record this change only.
Files in our working directory can be in one of two states: tracked or untracked.
Tracked files are files that git
knows about. They either were in the last snapshot (commit), or they are staged now (that is, they are in the staging area).
Untracked files are everything else — any files in our working directory that were not in our last snapshot (commit) and are not in our staging area.