You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/02-git-basics/sections/recording-changes.asc
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Remember that each file in your working directory can be in one of two states: _
7
7
Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged.
8
8
In short, tracked files are files that Git knows about.
9
9
10
-
Untracked files are everything else – any files in your working directory that were not in your last snapshot and are not in your staging area.
10
+
Untracked files are everything else -- any files in your working directory that were not in your last snapshot and are not in your staging area.
11
11
When you first clone a repository, all of your files will be tracked and unmodified because Git just checked them out and you haven't edited anything.
12
12
13
13
As you edit files, Git sees them as modified, because you've changed them since your last commit.
@@ -30,7 +30,7 @@ Your branch is up-to-date with 'origin/master'.
30
30
nothing to commit, working directory clean
31
31
----
32
32
33
-
This means you have a clean working directory – in other words, none of your tracked files are modified.
33
+
This means you have a clean working directory -- in other words, none of your tracked files are modified.
34
34
Git also doesn't see any untracked files, or they would be listed here.
35
35
Finally, the command tells you which branch you're on and informs you that it has not diverged from the same branch on the server.
36
36
For now, that branch is always ``master'', which is the default; you won't worry about it here.
@@ -85,7 +85,7 @@ Changes to be committed:
85
85
86
86
You can tell that it's staged because it's under the ``Changes to be committed'' heading.
87
87
If you commit at this point, the version of the file at the time you ran `git add` is what will be in the historical snapshot.
88
-
You may recall that when you ran `git init` earlier, you then ran `git add <files>` – that was to begin tracking files in your directory.(((git commands, init)))(((git commands, add)))
88
+
You may recall that when you ran `git init` earlier, you then ran `git add <files>` -- that was to begin tracking files in your directory.(((git commands, init)))(((git commands, add)))
89
89
The `git add` command takes a path name for either a file or a directory; if it's a directory, the command adds all the files in that directory recursively.
90
90
91
91
==== Staging Modified Files
@@ -111,10 +111,10 @@ Changes not staged for commit:
111
111
112
112
----
113
113
114
-
The `CONTRIBUTING.md` file appears under a section named ``Changes not staged for commit'' – which means that a file that is tracked has been modified in the working directory but not yet staged.
114
+
The `CONTRIBUTING.md` file appears under a section named ``Changes not staged for commit'' -- which means that a file that is tracked has been modified in the working directory but not yet staged.
115
115
To stage it, you run the `git add` command.
116
-
`git add` is a multipurpose command – you use it to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved.
117
-
It may be helpful to think of it more as ``add this content to the next commit'' rather than ``add this file to the project''.(((git commands, add)))
116
+
`git add` is a multipurpose command -- you use it to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved.
117
+
It may be helpful to think of it more as ``add precisely this content to the next commit'' rather than ``add this file to the project''.(((git commands, add)))
118
118
Let's run `git add` now to stage the `CONTRIBUTING.md` file, and then run `git status` again:
119
119
120
120
[source,console]
@@ -212,7 +212,7 @@ $ cat .gitignore
212
212
*~
213
213
----
214
214
215
-
The first line tells Git to ignore any files ending in ``.o'' or ``.a'' – object and archive files that may be the product of building your code.
215
+
The first line tells Git to ignore any files ending in ``.o'' or ``.a'' -- object and archive files that may be the product of building your code.
216
216
The second line tells Git to ignore all files whose names end with a tilde (`~`), which is used by many text editors such as Emacs to mark temporary files.
217
217
You may also include a log, tmp, or pid directory; automatically generated documentation; and so on.
218
218
Setting up a `.gitignore` file for your new repository before you get going is generally a good idea so you don't accidentally commit files that you really don't want in your Git repository.
@@ -270,10 +270,10 @@ It is beyond the scope of this book to get into the details of multiple `.gitign
270
270
[[_git_diff_staged]]
271
271
==== Viewing Your Staged and Unstaged Changes
272
272
273
-
If the `git status` command is too vague for you – you want to know exactly what you changed, not just which files were changed – you can use the `git diff` command.(((git commands, diff)))
273
+
If the `git status` command is too vague for you -- you want to know exactly what you changed, not just which files were changed -- you can use the `git diff` command.(((git commands, diff)))
274
274
We'll cover `git diff` in more detail later, but you'll probably use it most often to answer these two questions: What have you changed but not yet staged?
275
275
And what have you staged that you are about to commit?
276
-
Although `git status` answers those questions very generally by listing the file names, `git diff` shows you the exact lines added and removed – the patch, as it were.
276
+
Although `git status` answers those questions very generally by listing the file names, `git diff` shows you the exact lines added and removed -- the patch, as it were.
277
277
278
278
Let's say you edit and stage the `README` file again and then edit the `CONTRIBUTING.md` file without staging it.
279
279
If you run your `git status` command, you once again see something like this:
@@ -334,7 +334,7 @@ index 0000000..03902a1
334
334
+My Project
335
335
----
336
336
337
-
It's important to note that `git diff` by itself doesn't show all changes made since your last commit – only changes that are still unstaged.
337
+
It's important to note that `git diff` by itself doesn't show all changes made since your last commit -- only changes that are still unstaged.
338
338
This can be confusing, because if you've staged all of your changes, `git diff` will give you no output.
339
339
340
340
For another example, if you stage the `CONTRIBUTING.md` file and then edit it, you can use `git diff` to see the changes in the file that are staged and the changes that are unstaged.
@@ -409,7 +409,7 @@ Run `git difftool --tool-help` to see what is available on your system.
409
409
==== Committing Your Changes
410
410
411
411
Now that your staging area is set up the way you want it, you can commit your changes.
412
-
Remember that anything that is still unstaged – any files you have created or modified that you haven't run `git add` on since you edited them – won't go into this commit.
412
+
Remember that anything that is still unstaged -- any files you have created or modified that you haven't run `git add` on since you edited them -- won't go into this commit.
413
413
They will stay as modified files on your disk.
414
414
In this case, let's say that the last time you ran `git status`, you saw that everything was staged, so you're ready to commit your changes.(((git commands, status)))
415
415
The simplest way to commit is to type `git commit`:(((git commands, commit)))
@@ -420,7 +420,7 @@ $ git commit
420
420
----
421
421
422
422
Doing so launches your editor of choice.
423
-
(This is set by your shell's `EDITOR` environment variable – usually vim or emacs, although you can configure it with whatever you want using the `git config --global core.editor` command as you saw in <<_getting_started>>).(((editor, changing default)))(((git commands, config)))
423
+
(This is set by your shell's `EDITOR` environment variable -- usually vim or emacs, although you can configure it with whatever you want using the `git config --global core.editor` command as you saw in <<_getting_started>>).(((editor, changing default)))(((git commands, config)))
424
424
425
425
The editor displays the following text (this example is a Vim screen):
426
426
@@ -572,7 +572,7 @@ This command removes all files whose names end with a `~`.
572
572
(((files, moving)))
573
573
Unlike many other VCS systems, Git doesn't explicitly track file movement.
574
574
If you rename a file in Git, no metadata is stored in Git that tells it you renamed the file.
575
-
However, Git is pretty smart about figuring that out after the fact – we'll deal with detecting file movement a bit later.
575
+
However, Git is pretty smart about figuring that out after the fact -- we'll deal with detecting file movement a bit later.
576
576
577
577
Thus it's a bit confusing that Git has a `mv` command.
578
578
If you want to rename a file in Git, you can run something like:
@@ -607,5 +607,5 @@ $ git add README
607
607
----
608
608
609
609
Git figures out that it's a rename implicitly, so it doesn't matter if you rename a file that way or with the `mv` command.
610
-
The only real difference is that `git mv` is one command instead of three – it's a convenience function.
610
+
The only real difference is that `git mv` is one command instead of three -- it's a convenience function.
611
611
More importantly, you can use any tool you like to rename a file, and address the add/rm later, before you commit.
0 commit comments