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
+33-33Lines changed: 33 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ The `git add` command takes a path name for either a file or a directory; if it'
86
86
==== Staging Modified Files
87
87
88
88
Let's change a file that was already tracked.
89
-
If you change a previously tracked file called ``benchmarks.rb'' and then run your `git status` command again, you get something that looks like this:
89
+
If you change a previously tracked file called ``CONTRIBUTING.md'' and then run your `git status` command again, you get something that looks like this:
90
90
91
91
[source,console]
92
92
----
@@ -101,68 +101,68 @@ Changes not staged for commit:
101
101
(use "git add <file>..." to update what will be committed)
102
102
(use "git checkout -- <file>..." to discard changes in working directory)
103
103
104
-
modified: benchmarks.rb
104
+
modified: CONTRIBUTING.md
105
105
106
106
----
107
107
108
-
The ``benchmarks.rb'' file appears under a section named ``Changed but not staged for commit'' – which means that a file that is tracked has been modified in the working directory but not yet staged.
108
+
The ``CONTRIBUTING.md'' file appears under a section named ``Changed but not staged for commit'' – which means that a file that is tracked has been modified in the working directory but not yet staged.
109
109
To stage it, you run the `git add` command. `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. 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)))
110
-
Let's run `git add` now to stage the ``benchmarks.rb'' file, and then run `git status` again:
110
+
Let's run `git add` now to stage the ``CONTRIBUTING.md'' file, and then run `git status` again:
111
111
112
112
[source,console]
113
113
----
114
-
$ git add benchmarks.rb
114
+
$ git add CONTRIBUTING.md
115
115
$ git status
116
116
On branch master
117
117
Changes to be committed:
118
118
(use "git reset HEAD <file>..." to unstage)
119
119
120
120
new file: README
121
-
modified: benchmarks.rb
121
+
modified: CONTRIBUTING.md
122
122
123
123
----
124
124
125
125
Both files are staged and will go into your next commit.
126
-
At this point, suppose you remember one little change that you want to make in `benchmarks.rb` before you commit it.
126
+
At this point, suppose you remember one little change that you want to make in `CONTRIBUTING.md` before you commit it.
127
127
You open it again and make that change, and you're ready to commit.
128
128
However, let's run `git status` one more time:
129
129
130
130
[source,console]
131
131
----
132
-
$ vim benchmarks.rb
132
+
$ vim CONTRIBUTING.md
133
133
$ git status
134
134
On branch master
135
135
Changes to be committed:
136
136
(use "git reset HEAD <file>..." to unstage)
137
137
138
138
new file: README
139
-
modified: benchmarks.rb
139
+
modified: CONTRIBUTING.md
140
140
141
141
Changes not staged for commit:
142
142
(use "git add <file>..." to update what will be committed)
143
143
(use "git checkout -- <file>..." to discard changes in working directory)
144
144
145
-
modified: benchmarks.rb
145
+
modified: CONTRIBUTING.md
146
146
147
147
----
148
148
149
149
What the heck?
150
-
Now `benchmarks.rb` is listed as both staged _and_ unstaged.
150
+
Now `CONTRIBUTING.md` is listed as both staged _and_ unstaged.
151
151
How is that possible?
152
152
It turns out that Git stages a file exactly as it is when you run the `git add` command.
153
-
If you commit now, the version of `benchmarks.rb` as it was when you last ran the `git add` command is how it will go into the commit, not the version of the file as it looks in your working directory when you run `git commit`.
153
+
If you commit now, the version of `CONTRIBUTING.md` as it was when you last ran the `git add` command is how it will go into the commit, not the version of the file as it looks in your working directory when you run `git commit`.
154
154
If you modify a file after you run `git add`, you have to run `git add` again to stage the latest version of the file:
155
155
156
156
[source,console]
157
157
----
158
-
$ git add benchmarks.rb
158
+
$ git add CONTRIBUTING.md
159
159
$ git status
160
160
On branch master
161
161
Changes to be committed:
162
162
(use "git reset HEAD <file>..." to unstage)
163
163
164
164
new file: README
165
-
modified: benchmarks.rb
165
+
modified: CONTRIBUTING.md
166
166
----
167
167
168
168
==== Short Status
@@ -248,7 +248,7 @@ We'll cover `git diff` in more detail later, but you'll probably use it most oft
248
248
And what have you staged that you are about to commit?
249
249
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.
250
250
251
-
Let's say you edit and stage the `README` file again and then edit the `benchmarks.rb` file without staging it.
251
+
Let's say you edit and stage the `README` file again and then edit the `CONTRIBUTING.md` file without staging it.
252
252
If you run your `git status` command, you once again see something like this:
253
253
254
254
[source,console]
@@ -264,18 +264,18 @@ Changes not staged for commit:
264
264
(use "git add <file>..." to update what will be committed)
265
265
(use "git checkout -- <file>..." to discard changes in working directory)
266
266
267
-
modified: benchmarks.rb
267
+
modified: CONTRIBUTING.md
268
268
----
269
269
270
270
To see what you've changed but not yet staged, type `git diff` with no other arguments:
271
271
272
272
[source,console]
273
273
----
274
274
$ git diff
275
-
diff --git a/benchmarks.rb b/benchmarks.rb
275
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
276
276
index 3cb747f..e445e28 100644
277
-
--- a/benchmarks.rb
278
-
+++ b/benchmarks.rb
277
+
--- a/CONTRIBUTING.md
278
+
+++ b/CONTRIBUTING.md
279
279
@@ -36,6 +36,10 @@ def main
280
280
@commit.parents[0].parents[0].parents[0]
281
281
end
@@ -313,35 +313,35 @@ index 0000000..03902a1
313
313
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.
314
314
This can be confusing, because if you've staged all of your changes, `git diff` will give you no output.
315
315
316
-
For another example, if you stage the `benchmarks.rb` 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. If our environment looks like this:
316
+
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. If our environment looks like this:
317
317
318
318
[source,console]
319
319
----
320
-
$ git add benchmarks.rb
321
-
$ echo '# test line' >> benchmarks.rb
320
+
$ git add CONTRIBUTING.md
321
+
$ echo '# test line' >> CONTRIBUTING.md
322
322
$ git status
323
323
On branch master
324
324
Changes to be committed:
325
325
(use "git reset HEAD <file>..." to unstage)
326
326
327
-
modified: benchmarks.rb
327
+
modified: CONTRIBUTING.md
328
328
329
329
Changes not staged for commit:
330
330
(use "git add <file>..." to update what will be committed)
331
331
(use "git checkout -- <file>..." to discard changes in working directory)
332
332
333
-
modified: benchmarks.rb
333
+
modified: CONTRIBUTING.md
334
334
----
335
335
336
336
Now you can use `git diff` to see what is still unstaged
337
337
338
338
[source,console]
339
339
----
340
340
$ git diff
341
-
diff --git a/benchmarks.rb b/benchmarks.rb
341
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
342
342
index e445e28..86b2f7c 100644
343
-
--- a/benchmarks.rb
344
-
+++ b/benchmarks.rb
343
+
--- a/CONTRIBUTING.md
344
+
+++ b/CONTRIBUTING.md
345
345
@@ -127,3 +127,4 @@ end
346
346
main()
347
347
@@ -354,10 +354,10 @@ and `git diff --cached` to see what you've staged so far:
354
354
[source,console]
355
355
----
356
356
$ git diff --cached
357
-
diff --git a/benchmarks.rb b/benchmarks.rb
357
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
358
358
index 3cb747f..e445e28 100644
359
-
--- a/benchmarks.rb
360
-
+++ b/benchmarks.rb
359
+
--- a/CONTRIBUTING.md
360
+
+++ b/CONTRIBUTING.md
361
361
@@ -36,6 +36,10 @@ def main
362
362
@commit.parents[0].parents[0].parents[0]
363
363
end
@@ -405,7 +405,7 @@ The editor displays the following text (this example is a Vim screen):
405
405
# On branch master
406
406
# Changes to be committed:
407
407
# new file: README
408
-
# modified: benchmarks.rb
408
+
# modified: CONTRIBUTING.md
409
409
#
410
410
~
411
411
~
@@ -451,15 +451,15 @@ Changes not staged for commit:
451
451
(use "git add <file>..." to update what will be committed)
452
452
(use "git checkout -- <file>..." to discard changes in working directory)
453
453
454
-
modified: benchmarks.rb
454
+
modified: CONTRIBUTING.md
455
455
456
456
no changes added to commit (use "git add" and/or "git commit -a")
457
457
$ git commit -a -m 'added new benchmarks'
458
458
[master 83e38c7] added new benchmarks
459
459
1 file changed, 5 insertions(+), 0 deletions(-)
460
460
----
461
461
462
-
Notice how you don't have to run `git add` on the ``benchmarks.rb'' file in this case before you commit.
462
+
Notice how you don't have to run `git add` on the ``CONTRIBUTING.md'' file in this case before you commit.
Copy file name to clipboardExpand all lines: book/02-git-basics/sections/undoing.asc
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,17 +49,17 @@ Changes to be committed:
49
49
(use "git reset HEAD <file>..." to unstage)
50
50
51
51
renamed: README.md -> README
52
-
modified: benchmarks.rb
52
+
modified: CONTRIBUTING.md
53
53
----
54
54
55
55
Right below the ``Changes to be committed'' text, it says use `git reset HEAD <file>...` to unstage.
56
-
So, let's use that advice to unstage the `benchmarks.rb` file:
56
+
So, let's use that advice to unstage the `CONTRIBUTING.md` file:
57
57
58
58
[source,console]
59
59
----
60
-
$ git reset HEAD benchmarks.rb
60
+
$ git reset HEAD CONTRIBUTING.md
61
61
Unstaged changes after reset:
62
-
M benchmarks.rb
62
+
M CONTRIBUTING.md
63
63
$ git status
64
64
On branch master
65
65
Changes to be committed:
@@ -71,11 +71,11 @@ Changes not staged for commit:
71
71
(use "git add <file>..." to update what will be committed)
72
72
(use "git checkout -- <file>..." to discard changes in working directory)
73
73
74
-
modified: benchmarks.rb
74
+
modified: CONTRIBUTING.md
75
75
----
76
76
77
77
The command is a bit strange, but it works.
78
-
The `benchmarks.rb` file is modified but once again unstaged.
78
+
The `CONTRIBUTING.md` file is modified but once again unstaged.
79
79
80
80
[NOTE]
81
81
=====
@@ -86,7 +86,7 @@ For now this magic invocation is all you need to know about the `git reset` comm
86
86
87
87
==== Unmodifying a Modified File
88
88
89
-
What if you realize that you don't want to keep your changes to the `benchmarks.rb` file?
89
+
What if you realize that you don't want to keep your changes to the `CONTRIBUTING.md` file?
90
90
How can you easily unmodify it – revert it back to what it looked like when you last committed (or initially cloned, or however you got it into your working directory)?
91
91
Luckily, `git status` tells you how to do that, too.
92
92
In the last example output, the unstaged area looks like this:
@@ -97,15 +97,15 @@ Changes not staged for commit:
97
97
(use "git add <file>..." to update what will be committed)
98
98
(use "git checkout -- <file>..." to discard changes in working directory)
99
99
100
-
modified: benchmarks.rb
100
+
modified: CONTRIBUTING.md
101
101
----
102
102
103
103
It tells you pretty explicitly how to discard the changes you've made.
0 commit comments