-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliaoxuefeng.html
1490 lines (1265 loc) · 99.8 KB
/
liaoxuefeng.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!-- saved from url=(0133)http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000 -->
<html xmlns:itranswarp="http://www.itranswarp.com/" xmlns:wb="http://open.weibo.com/wb" class="uk-notouch"><!--
--><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>工作区和暂存区 - 廖雪峰的官方网站</title>
<meta name="viewport" content="width=device-width">
<meta name="keywords" content="javascript,node,jquery,git,python,java,sql,linux,ios,android,教程,软件,编程,开发,运维,网络,互联网">
<meta name="description" content="研究互联网产品和技术,提供原创中文精品教程">
<meta property="x-nav" content=" /wiki/0013739516305929606dd18361248578c67b8067c8c017b000 ">
<link rel="alternate" href="http://www.liaoxuefeng.com/feed" title="廖雪峰的官方网站" type="application/rss+xml">
<meta property="og:type" content="article">
<meta property="og:url" content="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000">
<meta property="og:title" content="工作区和暂存区">
<meta property="og:description" content="史上最浅显易懂的Git教程">
<meta property="og:image" content="http://www.liaoxuefeng.com/files/attachments/001385348516246a18bd54b498f4c74b694624d67f02fa9000/l">
<!-- BEGIN CSS COMPRESS -->
<link rel="stylesheet" href="./liaoxuefeng_files/codemirror.css">
<link rel="stylesheet" href="./liaoxuefeng_files/highlight.css">
<link rel="stylesheet" href="./liaoxuefeng_files/itranswarp.css">
<!-- END CSS COMPRESS -->
<!--[if lt IE 9]>
<link rel="stylesheet" href="/static/themes/default/css/ie.css" />
<![endif]-->
<script src="./liaoxuefeng_files/underscore.js"></script><script src="./liaoxuefeng_files/ca-pub-6727358730461554.js"></script><script src="./liaoxuefeng_files/hm.js"></script><script src="./liaoxuefeng_files/all.js"></script>
<script id="tplComment" type="text/plain">
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="/user/{ user.id }"><img class="uk-comment-avatar uk-border-circle x-avatar" src="{ user.image_url }" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="/discuss/{ board_id }/{ id }">{ name }</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="/user/{ user.id }">{ user.name }</a> created at { created_at.toSmartDate() }, Last updated at { updated_at.toSmartDate() }</div>
</div>
<div class="uk-comment-body x-auto-content">
{ content|safe }
</div>
</div>
</script>
<script id="tplCommentReply" type="text/plain">
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="/user/{ user.id }"><img class="uk-comment-avatar uk-border-circle x-avatar" src="{ user.image_url }" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="/user/{ user.id }">{ user.name }</a></div>
<div class="uk-comment-meta">Created at { created_at.toSmartDate() }, Last updated at { updated_at.toSmartDate() }</div>
</div>
<div class="uk-comment-body x-auto-content">
{ content|safe }
</div>
</div>
</script>
<script id="tplCommentInfo" type="text/plain">
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="/discuss/{ board_id }/{ id }"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="/discuss/{ board_id }/{ id }#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</script>
<script id="tplCommentArea" type="text/plain">
<div class="x-display-if-signin">
<p><button id="comment-make-button" type="button" class="uk-button uk-button-primary"><i class="uk-icon-comment"></i> 发表评论</button></p>
<form id="comment-form" class="uk-form" style="display:none;">
<fieldset>
<div class="uk-alert uk-alert-danger" style="display:none"></div>
<div class="uk-form-row">
<label>标题:</label>
</div>
<div class="uk-form-row">
<input type="text" name="name" maxlength="100" style="width:100%">
</div>
<div class="uk-form-row">
<label>内容:</label>
</div>
<div class="uk-form-row x-textarea">
</div>
<div class="uk-form-row">
<button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-check"></i> 发布</button>
<button type="button" class="uk-button x-cancel"><i class="uk-icon-close"></i> 取消</button>
</div>
</fieldset>
</form>
</div>
</script>
<style id="x-doc-style">
.x-display-if-signin { display: none; }
</style>
<script>
var g_time = parseFloat('1487171979828');
var g_signins = [{"id":"weibo","icon":"weibo","name":"使用新浪微博登录"}];
//
var g_user = null;
//
</script>
<style>
.x-wiki-visible {
display: block;
}
</style>
<script>
loadComments('0013745374151782eb658c5a5ca454eaa451661275886c6000');
var
comment_type = 'wikipage',
comment_ref_id = '0013745374151782eb658c5a5ca454eaa451661275886c6000',
comment_tag = 'git';
function onAuthSuccess() {
initCommentArea(comment_type, comment_ref_id, comment_tag);
}
$(function () {
if (g_user !== null) {
initCommentArea(comment_type, comment_ref_id, comment_tag);
}
});
$(function () {
var
current = $('#0013745374151782eb658c5a5ca454eaa451661275886c6000'),
prev = current.prev().find('a'),
next = current.next().find('a'),
L = [];
current.addClass('uk-active');
$('#off-0013745374151782eb658c5a5ca454eaa451661275886c6000').addClass('uk-active');
L.push('<div class="uk-clearfix uk-margin-left uk-margin-right">');
if (prev.length > 0) {
L.push('<span class="uk-float-left"><i class="uk-icon-chevron-left"></i> <a href="');
L.push(prev.attr('href'));
L.push('">');
L.push(encodeHtml(prev.text()));
L.push('</a></span>');
}
if (next.length > 0) {
L.push('<span class="uk-float-right"><a href="');
L.push(next.attr('href'));
L.push('">');
L.push(encodeHtml(next.text()));
L.push('</a> <i class="uk-icon-chevron-right"></i></span>')
}
L.push('</div>');
$('#x-wiki-prev-next').html(L.join(''));
});
</script>
<style>
.x-center {
margin: 0;
}
.x-center {
margin-left: 316px;
padding-left: 15px;
}
</style>
<!-- BEGIN custom_header -->
<script src="./liaoxuefeng_files/wb.js" type="text/javascript" charset="utf-8"></script>
<script>
// git: add app link:
$(function() {
if (location.pathname.indexOf('/wiki/0013739516305929606dd18361248578c67b8067c8c017b000')===0) {
$('.x-wiki-info').parent().css('position', 'relative').append('<a href="/webpage/gitapp" target="_blank" style="display:block;width:135px;height:40px;position:absolute;right:10px;top:10px;"><img src="/static/img/download-on-the-app-store.png" /></a>');
}
// add new:
$('#ul-navbar a[href="/webpage/java"]').parent().append('<img style="position:absolute;right:-10px;top:3px;z-index:999" src="/files/attachments/001477919415261ebc91072244149e0ab69f60ae2abe39f000/l">');
});
</script>
<script>
// python 3: add 2.7 link:
$(function() {
if (location.pathname.indexOf('/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000')===0) {
$('.x-wiki-info').parent().css('position', 'relative').append('<a href="/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000" target="_blank" style="display:block;position:absolute;right:10px;top:10px;">2.7旧版教程</a>');
}
});
</script>
<script>
// python 2.7: add py3 link:
$(function() {
if (location.pathname.indexOf('/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000')===0) {
$('#main .x-container').prepend('<div class="uk-alert uk-alert-danger">您目前正在学习的2.7版本的Python教程已过期,请立刻前往最新的Python 3 教程:<a href="/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000" class="uk-button uk-button-success">我要学 Python 3</a></div>');
}
});
</script>
<script>
// the ad:
$(function() {
var _a_pros = [
{
id: 'zhufeng',
href: 'http://www.zhufengpeixun.cn/customize/node/index.html',
img: '/files/attachments/0014836214192874d51988d2bf544e5bfecae1c63fafa5f000/0'
},
{
id: 'maiziedu',
href: 'http://www.maizitime.com/pages/adpc/python.html?yy=lxfpy',
img: '/files/attachments/001468226657174e6b109d28e84442798a2a4451e7b2dea000/0'
},
{
id: 'xitu',
href: 'http://gold.xitu.io/welcome?utm_source=liaoxuefeng&utm_medium=banner&utm_content=gaoshou&utm_campaign=q3_personal',
img: '/files/attachments/00146917760141137418dc990d3459d99ea875458da0ea4000/0'
},
{
id: 'julyedu',
href: 'https://www.julyedu.com/course/getDetail/51?source=lxf',
img: '/files/attachments/001485445378529cc4a749e17f84a46a0db28de92a0bc58000/0'
}
];
var _b_pros = {
id: 'julyedu',
href: 'https://www.julyedu.com/sale/vip?source=lxf',
img: '/files/attachments/001485319581354de479f06897e43a8bb1ecb7e1412fd86000/0'
};
var _c_pros = {
id: 'ccc',
href: 'http://xxx',
img: '/files/attachments/xxx/0'
};
$('div.x-promo-b').html('<div style="width:300px;height:600px"><a target="_blank" href="' + _b_pros.href + '" onclick="_hmt.push([\'_trackEvent\', \'' + _b_pros.id + '\', \'click\', \'clicked\']);"><img src="' + _b_pros.img + '" style="width:300px;height:600px"></a></div>' + '<!-- <div style="width:300px;height:250px"><a target="_blank" href="' + _c_pros.href + '" onclick="_hmt.push([\'_trackEvent\', \'' + _c_pros.id + '\', \'click\', \'clicked\']);"><img src="' + _c_pros.img + '" style="width:300px;height:250px"></a></div> -->');
var i, s = '';
for (i=0; i<_a_pros.length; i++) {
s = s + '<div style="width:336px;height:280px;float:left;"><a target="_blank" href="' + _a_pros[i].href + '" onclick="_hmt.push([\'_trackEvent\', \'' + _a_pros[i].id + '\', \'click\', \'clicked\']);"><img src="' + _a_pros[i].img + '" style="width:336px;height:280px"></a></div>';
}
if (location.pathname.indexOf('/wiki/')===0 || location.pathname.indexOf('/article/')===0) {
s = s + '<div style="clear: both;"></div>';
$('.x-wiki-content').after(s);
$('.x-article-content').after(s);
}
else {
$('#the-promos').prepend(s);
}
});
</script>
<script>
// add share:
$(function() {
if (location.pathname.indexOf('/wiki/')===0) {
$('.x-wiki-content').find('a[href^=http]').attr('target', '_blank');
if (!window.hurry) {
$('.x-wiki-content').after('<h3>感觉本站内容不错,读后有收获?</h3><p><a target="_blank" href="/webpage/donate" class="uk-button uk-button-primary"><i class="uk-icon-cny"></i> 我要小额赞助,鼓励作者写出更好的教程</a></p><h3>还可以分享给朋友</h3><p><wb:share-button appkey="1391944217" addition="full" type="button" ralateUid="1658384301" picture_search="false" pic="' + $('meta[property="og:image"]').attr('content') + '"></wb:share-button></p>');
} else {
$('.x-wiki-content').after('<h3>等待时间太久?</h3><p><a target="_blank" href="/webpage/donate" class="uk-button uk-button-primary"><i class="uk-icon-cny"></i> 我要催促作者更新教程</a></p><h3>还可以分享给朋友</h3><p><wb:share-button appkey="1391944217" addition="full" type="button" ralateUid="1658384301" picture_search="false" pic="' + $('meta[property="og:image"]').attr('content') + '"></wb:share-button></p>');
}
}
if (location.pathname.indexOf('/discuss/')===0) {
var r = parseQueryString();
if (!r.page || r.page==='1') {
$('div.x-content>div.uk-comment:first div.uk-comment-body').append('<hr><p class="uk-text-muted">想要问题快速得到解答?分享给朋友试试:</p><p><wb:share-button appkey="1391944217" addition="full" type="button" ralateUid="1658384301" picture_search="false"></wb:share-button></p>');
}
}
});
</script>
<script>
// article: add share:
$(function() {
if (location.pathname.indexOf('/article/')===0) {
$('.x-article-content').find('a[href^=http]').attr('target', '_blank');
$('.x-article-content').after('<h3>感觉本站内容不错,读后有收获?</h3><p><a target="_blank" href="/webpage/donate" class="uk-button uk-button-primary"><i class="uk-icon-cny"></i> 我要小额赞助,鼓励作者写出更好的文章</a></p><h3>还可以分享给朋友</h3><p><wb:share-button appkey="1391944217" addition="full" type="button" ralateUid="1658384301" picture_search="false" pic="' + $('meta[property="og:image"]').attr('content') + '"></wb:share-button></p>');
}
});
</script>
<script>
// all:
$(function() {
$('.x-footer-copyright').find('p').append('<br>由<a target="_blank" href="http://s.click.taobao.com/t?e=m%3D2%26s%3DuVSSwb68TEYcQipKwQzePCperVdZeJviEViQ0P1Vf2kguMN8XjClAouhd4loqGpDWNI3LssOJ1ZIW%2FH7aX8LI9nQCCjrrrN3wYAeXhmRFOHMh3DDj7e5Hudn1BbglxZYxUhy8exlzcpAFEHVckI7b93srg%2FL%2FeD3keUEnoKELDlWYetMiZZgV%2BSx6OrKqagyklzFeKMz7Cd4Qek9OyREefaKWlxOHSq5XF%2B87KN7TKeiZ%2BQMlGz6FQ%3D%3D">阿里云</a>托管<br><a href="#0" onclick="location.assign(decodeURIComponent(\'moc.36104%fxlksaA3%otliam\'.split(\'\').reverse().join(\'\')))">广告合作</a>');
$('.x-footer').append('<hr><div style="text-align:center"><p>友情链接: <a href="http://www.shi-ci.com" target="_blank">中华诗词</a> - <a href="http://s.click.taobao.com/t?e=m%3D2%26s%3DjPaT%2Fmi2tL4cQipKwQzePCperVdZeJviEViQ0P1Vf2kguMN8XjClAlFz4nQbUpKuV%2FZ67c680w5IW%2FH7aX8LI9nQCCjrrrN3wYAeXhmRFOHMh3DDj7e5Hudn1BbglxZYxUhy8exlzcq9AmARIwX9K%2BnbtOD3UdznPV1H2z0iQv9NkKVMHClW0QbMqOpFMIvnvjQXzzpXdTHGJe8N%2FwNpGw%3D%3D" target="_blank">阿里云</a> - <a href="http://mitpress.mit.edu/sicp/full-text/book/book.html" target="_blank">SICP</a> - <a href="http://www.4clojure.com/" target="_blank">4clojure</a></p></div>');
});
</script>
<script>
// tongji:
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?2efddd14a5f2b304677462d06fb4f964";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<script>
$(function() {
var x = document.createElement('script');
x.src = '/static/js/underscore.js';
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(x, s);
});
</script>
<!-- END custom_header -->
<script charset="UTF-8" src="./liaoxuefeng_files/bundle.js"></script><script charset="UTF-8" src="./liaoxuefeng_files/iframeWidget.js"></script></head>
<body><div id="BAIDU_DUP_fp_wrapper" style="position: absolute; left: -1px; bottom: -1px; z-index: 0; width: 0px; height: 0px; overflow: hidden; visibility: hidden; display: none;"><iframe id="BAIDU_DUP_fp_iframe" src="./liaoxuefeng_files/o.html" style="width: 0px; height: 0px; visibility: hidden; display: none;"></iframe></div><iframe id="sina_anywhere_iframe" style="display: none;"></iframe>
<div class="x-goto-top" style="display: none;">
<div class="x-arrow"></div>
<div class="x-stick"></div>
</div>
<div id="header" class="uk-navbar uk-navbar-attached">
<div class="uk-container x-container">
<div class="uk-navbar uk-navbar-attached">
<ul class="uk-navbar-nav uk-visible-small">
<li><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000#0" onclick="UIkit.offcanvas.show('#x-offcanvas-left')"><i class="uk-icon-chevron-right"></i></a></li>
</ul>
<a href="http://www.liaoxuefeng.com/" class="uk-navbar-brand uk-visible-large">廖雪站</a>
<a href="http://www.liaoxuefeng.com/" class="uk-navbar-brand uk-hidden-large"><i class="uk-icon-home"></i></a>
<ul id="ul-navbar" class="uk-navbar-nav uk-hidden-small">
<li><a href="http://www.liaoxuefeng.com/category/0013738748415562fee26e070fa4664ad926c8e30146c67000">编程</a></li>
<li><a href="http://www.liaoxuefeng.com/category/0013738748248885ddf38d8cd1b4803aa74bcda32f853fd000">读书</a></li>
<li><a href="http://www.liaoxuefeng.com/webpage/java">Java教程</a><img style="position:absolute;right:-10px;top:3px;z-index:999" src="./liaoxuefeng_files/l"></li>
<li><a href="http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000">JavaScript教程</a></li>
<li><a href="http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000">Python教程</a></li>
<li class="uk-active"><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000">Git教程</a></li>
<li><a href="http://www.liaoxuefeng.com/discuss">问答</a></li>
<li><a href="http://www.liaoxuefeng.com/webpage/donate">赞助</a></li>
</ul>
<ul class="uk-navbar-nav uk-visible-small">
<li class="uk-parent" data-uk-dropdown="">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000#0"><i class="uk-icon-navicon"></i></a>
<div class="uk-dropdown uk-dropdown-navbar">
<ul class="uk-nav uk-nav-navbar">
<li><a href="http://www.liaoxuefeng.com/category/0013738748415562fee26e070fa4664ad926c8e30146c67000">编程</a></li>
<li><a href="http://www.liaoxuefeng.com/category/0013738748248885ddf38d8cd1b4803aa74bcda32f853fd000">读书</a></li>
<li><a href="http://www.liaoxuefeng.com/webpage/java">Java教程</a></li>
<li><a href="http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000">JavaScript教程</a></li>
<li><a href="http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000">Python教程</a></li>
<li><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000">Git教程</a></li>
<li><a href="http://www.liaoxuefeng.com/discuss">问答</a></li>
<li><a href="http://www.liaoxuefeng.com/webpage/donate">赞助</a></li>
</ul>
</div>
</li>
</ul>
<!--
<div class="uk-navbar-content x-hidden-tiny">
<form id="form-search" class="uk-form uk-margin-remove uk-display-inline-block">
<div class="uk-form-icon">
<i class="uk-icon-search"></i>
<input type="text" placeholder="Search">
</div>
</form>
</div>
-->
<div class="uk-navbar-flip">
<ul class="uk-navbar-nav">
<li class="uk-parent x-display-if-signin" data-uk-dropdown="">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000#0"><i class="uk-icon-user"></i><span class="x-hidden-tiny"> </span><span class="x-user-name x-hidden-tiny"></span></a>
<div class="uk-dropdown uk-dropdown-navbar">
<ul class="uk-nav uk-nav-navbar">
<li><a target="_blank" href="http://www.liaoxuefeng.com/me/profile"><i class="uk-icon-cogs"></i> 个人资料</a></li>
<li class="uk-nav-divider"></li>
<li><a href="http://www.liaoxuefeng.com/auth/signout"><i class="uk-icon-power-off"></i> 登出</a></li>
</ul>
</div>
</li>
<li class="x-display-if-not-signin uk-hidden-small"><a href="javascript:showSignin()"><i class="uk-icon-sign-in"></i> 登录</a></li>
<li class="x-display-if-not-signin uk-visible-small"><a href="javascript:showSignin()"><i class="uk-icon-sign-in"></i></a></li>
</ul>
</div>
</div>
</div>
</div><!-- // header -->
<div id="main">
<div class="x-placeholder-50"><!-- placeholder --></div>
<div class="x-placeholder"><!-- placeholder --></div>
<div class="uk-container x-container">
<div class="uk-grid">
<div class="x-body-before uk-width-1-1">
</div>
</div>
<div class="uk-grid">
<div class="uk-width-1-1">
<div class="x-sidebar-left">
<div class="x-sidebar-left-top">
</div>
<div class="x-sidebar-left-content">
<ul class="uk-nav uk-nav-side">
<li class="uk-nav-header">目录</li>
</ul>
<ul class="uk-nav uk-nav-side" style="margin-right:-15px;">
<li id="0013739516305929606dd18361248578c67b8067c8c017b000"><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000">Git教程</a></li>
<li id="001373962845513aefd77a99f4145f0a2c7a7ca057e7570000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001373962845513aefd77a99f4145f0a2c7a7ca057e7570000">Git简介</a>
</li>
<li id="00137402760310626208b4f695940a49e5348b689d095fc000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137402760310626208b4f695940a49e5348b689d095fc000">Git的诞生</a>
</li>
<li id="001374027586935cf69c53637d8458c9aec27dd546a6cd6000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374027586935cf69c53637d8458c9aec27dd546a6cd6000">集中式vs分布式</a>
</li>
<li id="00137396287703354d8c6c01c904c7d9ff056ae23da865a000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137396287703354d8c6c01c904c7d9ff056ae23da865a000">安装Git</a>
</li>
<li id="0013743256916071d599b3aed534aaab22a0db6c4e07fd0000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743256916071d599b3aed534aaab22a0db6c4e07fd0000">创建版本库</a>
</li>
<li id="0013743858312764dca7ad6d0754f76aa562e3789478044000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743858312764dca7ad6d0754f76aa562e3789478044000">时光机穿梭</a>
</li>
<li id="0013744142037508cf42e51debf49668810645e02887691000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000">版本回退</a>
</li>
<li id="0013745374151782eb658c5a5ca454eaa451661275886c6000" style="margin-left:2em;" class="uk-active">
<a href="./liaoxuefeng_files/liaoxuefeng.html">工作区和暂存区</a>
</li>
<li id="001374829472990293f16b45df14f35b94b3e8a026220c5000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374829472990293f16b45df14f35b94b3e8a026220c5000">管理修改</a>
</li>
<li id="001374831943254ee90db11b13d4ba9a73b9047f4fb968d000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374831943254ee90db11b13d4ba9a73b9047f4fb968d000">撤销修改</a>
</li>
<li id="0013758392816224cafd33c44b4451887cc941e6716805c000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013758392816224cafd33c44b4451887cc941e6716805c000">删除文件</a>
</li>
<li id="001374385852170d9c7adf13c30429b9660d0eb689dd43a000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374385852170d9c7adf13c30429b9660d0eb689dd43a000">远程仓库</a>
</li>
<li id="0013752340242354807e192f02a44359908df8a5643103a000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013752340242354807e192f02a44359908df8a5643103a000">添加远程库</a>
</li>
<li id="001375233990231ac8cf32ef1b24887a5209f83e01cb94b000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375233990231ac8cf32ef1b24887a5209f83e01cb94b000">从远程库克隆</a>
</li>
<li id="0013743862006503a1c5bf5a783434581661a3cc2084efa000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743862006503a1c5bf5a783434581661a3cc2084efa000">分支管理</a>
</li>
<li id="001375840038939c291467cc7c747b1810aab2fb8863508000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840038939c291467cc7c747b1810aab2fb8863508000">创建与合并分支</a>
</li>
<li id="001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000">解决冲突</a>
</li>
<li id="0013758410364457b9e3d821f4244beb0fd69c61a185ae0000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013758410364457b9e3d821f4244beb0fd69c61a185ae0000">分支管理策略</a>
</li>
<li id="00137602359178794d966923e5c4134bc8bf98dfb03aea3000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000">Bug分支</a>
</li>
<li id="001376026233004c47f22a16d1f4fa289ce45f14bbc8f11000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001376026233004c47f22a16d1f4fa289ce45f14bbc8f11000">Feature分支</a>
</li>
<li id="0013760174128707b935b0be6fc4fc6ace66c4f15618f8d000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013760174128707b935b0be6fc4fc6ace66c4f15618f8d000">多人协作</a>
</li>
<li id="0013762144381812a168659b3dd4610b4229d81de5056cc000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013762144381812a168659b3dd4610b4229d81de5056cc000">标签管理</a>
</li>
<li id="001376951758572072ce1dc172b4178b910d31bc7521ee4000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001376951758572072ce1dc172b4178b910d31bc7521ee4000">创建标签</a>
</li>
<li id="001376951885068a0ac7d81c3a64912b35a59b58a1d926b000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001376951885068a0ac7d81c3a64912b35a59b58a1d926b000">操作标签</a>
</li>
<li id="00137628548491051ccfaef0ccb470894c858999603fedf000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137628548491051ccfaef0ccb470894c858999603fedf000">使用GitHub</a>
</li>
<li id="00137621280731812dec22ecc9b44f4b2ca1c680f181a5b000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137621280731812dec22ecc9b44f4b2ca1c680f181a5b000">自定义Git</a>
</li>
<li id="0013758404317281e54b6f5375640abbb11e67be4cd49e0000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013758404317281e54b6f5375640abbb11e67be4cd49e0000">忽略特殊文件</a>
</li>
<li id="001375234012342f90be1fc4d81446c967bbdc19e7c03d3000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375234012342f90be1fc4d81446c967bbdc19e7c03d3000">配置别名</a>
</li>
<li id="00137583770360579bc4b458f044ce7afed3df579123eca000" style="margin-left:2em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579bc4b458f044ce7afed3df579123eca000">搭建Git服务器</a>
</li>
<li id="00137586810169600f39e17409a4358b1ac0d3621356287000" style="margin-left:1em;">
<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137586810169600f39e17409a4358b1ac0d3621356287000">期末总结</a>
</li>
</ul>
<div class="x-placeholder"></div>
</div>
<div class="x-sidebar-left-bottom">
<h3>关于作者</h3>
<iframe width="100%" height="90" class="share_self" frameborder="0" scrolling="no" src="./liaoxuefeng_files/index.html"></iframe>
<div class="x-promo-b" style="width:100%;overflow-x:hidden;margin-bottom:5px"><div style="width:300px;height:600px"><a target="_blank" href="https://www.julyedu.com/sale/vip?source=lxf" onclick="_hmt.push(['_trackEvent', 'julyedu', 'click', 'clicked']);"><img src="./liaoxuefeng_files/0" style="width:300px;height:600px"></a></div><!-- <div style="width:300px;height:250px"><a target="_blank" href="http://xxx" onclick="_hmt.push(['_trackEvent', 'ccc', 'click', 'clicked']);"><img src="/files/attachments/xxx/0" style="width:300px;height:250px"></a></div> --></div>
<div style="width:100%;overflow-x:hidden;">
<script async="" src="./liaoxuefeng_files/adsbygoogle.js"></script>
<!-- 300x600-lxf -->
<ins class="adsbygoogle" style="display:inline-block;width:300px;height:600px" data-ad-client="ca-pub-6727358730461554" data-ad-slot="4769867116" data-adsbygoogle-status="done"><ins id="aswift_0_expand" style="display:inline-table;border:none;height:600px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><ins id="aswift_0_anchor" style="display:block;border:none;height:600px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><iframe width="300" height="600" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe></ins></ins></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<div style="width:100%;overflow-x:hidden;">
<script type="text/javascript">
/*300x250 @baidu*/
var cpro_id = "u2060917";
</script>
<script src="./liaoxuefeng_files/c.js" type="text/javascript"></script><div id="BAIDU_SSP__wrapper_u2060917_0"><iframe id="iframeu2060917_0" src="./liaoxuefeng_files/tcam.html" width="300" height="250" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" style="border:0; vertical-align:bottom;margin:0;" allowtransparency="true"></iframe></div>
</div>
</div>
</div>
<div class="x-center">
<div>
</div>
<div class="x-content" style="width: 100%; position: relative;">
<h4>工作区和暂存区</h4>
<div class="x-wiki-info"><span>阅读: 572037</span></div>
<hr>
<div class="x-wiki-content">
<p>Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念。</p>
<p>先来看名词解释。</p>
<h4 id="-working-directory-">工作区(Working Directory)</h4>
<p>就是你在电脑里能看到的目录,比如我的<code>learngit</code>文件夹就是一个工作区:</p>
<p><img src="./liaoxuefeng_files/0(1)" alt="working-dir"></p>
<h4 id="-repository-">版本库(Repository)</h4>
<p>工作区有一个隐藏目录<code>.git</code>,这个不算工作区,而是Git的版本库。</p>
<p>Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支<code>master</code>,以及指向<code>master</code>的一个指针叫<code>HEAD</code>。</p>
<p><img src="./liaoxuefeng_files/0(2)" alt="git-repo"></p>
<p>分支和<code>HEAD</code>的概念我们以后再讲。</p>
<p>前面讲了我们把文件往Git版本库里添加的时候,是分两步执行的:</p>
<p>第一步是用<code>git add</code>把文件添加进去,实际上就是把文件修改添加到暂存区;</p>
<p>第二步是用<code>git commit</code>提交更改,实际上就是把暂存区的所有内容提交到当前分支。</p>
<p>因为我们创建Git版本库时,Git自动为我们创建了唯一一个<code>master</code>分支,所以,现在,<code>git commit</code>就是往<code>master</code>分支上提交更改。</p>
<p>你可以简单理解为,需要提交的文件修改通通放到暂存区,然后,一次性提交暂存区的所有修改。</p>
<p>俗话说,实践出真知。现在,我们再练习一遍,先对<code>readme.txt</code>做个修改,比如加上一行内容:</p>
<pre><code class="python">Git <span class="keyword">is</span> a distributed version control system.
Git <span class="keyword">is</span> free software distributed under the GPL.
Git has a mutable index called stage.
</code></pre><p>然后,在工作区新增一个<code>LICENSE</code>文本文件(内容随便写)。</p>
<p>先用<code>git status</code>查看一下状态:</p>
<pre><code class="ruby"><span class="variable">$ </span>git status
<span class="comment"># On branch master</span>
<span class="comment"># Changes not staged for commit:</span>
<span class="comment"># (use "git add <file>..." to update what will be committed)</span>
<span class="comment"># (use "git checkout -- <file>..." to discard changes in working directory)</span>
<span class="comment">#</span>
<span class="comment"># modified: readme.txt</span>
<span class="comment">#</span>
<span class="comment"># Untracked files:</span>
<span class="comment"># (use "git add <file>..." to include in what will be committed)</span>
<span class="comment">#</span>
<span class="comment"># LICENSE</span>
no changes added to commit (use <span class="string">"git add"</span> <span class="keyword">and</span>/<span class="keyword">or</span> <span class="string">"git commit -a"</span>)
</code></pre><p>Git非常清楚地告诉我们,<code>readme.txt</code>被修改了,而<code>LICENSE</code>还从来没有被添加过,所以它的状态是<code>Untracked</code>。</p>
<p>现在,使用两次命令<code>git add</code>,把<code>readme.txt</code>和<code>LICENSE</code>都添加后,用<code>git status</code>再查看一下:</p>
<pre><code class="ruby"><span class="variable">$ </span>git status
<span class="comment"># On branch master</span>
<span class="comment"># Changes to be committed:</span>
<span class="comment"># (use "git reset HEAD <file>..." to unstage)</span>
<span class="comment">#</span>
<span class="comment"># new file: LICENSE</span>
<span class="comment"># modified: readme.txt</span>
<span class="comment">#</span>
</code></pre><p>现在,暂存区的状态就变成这样了:</p>
<p><img src="./liaoxuefeng_files/0(3)" alt="git-stage"></p>
<p>所以,<code>git add</code>命令实际上就是把要提交的所有修改放到暂存区(Stage),然后,执行<code>git commit</code>就可以一次性把暂存区的所有修改提交到分支。</p>
<pre><code class="sql">$ git <span class="operator"><span class="keyword">commit</span> -m <span class="string">"understand how stage works"</span>
[master <span class="number">27</span>c9860] understand how stage works
<span class="number">2</span> files changed, <span class="number">675</span> insertions(+)
<span class="keyword">create</span> mode <span class="number">100644</span> LICENSE
</span></code></pre><p>一旦提交后,如果你又没有对工作区做任何修改,那么工作区就是“干净”的:</p>
<pre><code class="ruby"><span class="variable">$ </span>git status
<span class="comment"># On branch master</span>
nothing to commit (working directory clean)
</code></pre><p>现在版本库变成了这样,暂存区就没有任何内容了:</p>
<p><img src="./liaoxuefeng_files/0(4)" alt="git-stage-after-commit"></p>
<h3 id="-">小结</h3>
<p>暂存区是Git非常重要的概念,弄明白了暂存区,就弄明白了Git的很多操作到底干了什么。</p>
<p>没弄明白暂存区是怎么回事的童鞋,请向上滚动页面,再看一次。</p>
</div><h3>感觉本站内容不错,读后有收获?</h3><p><a target="_blank" href="http://www.liaoxuefeng.com/webpage/donate" class="uk-button uk-button-primary"><i class="uk-icon-cny"></i> 我要小额赞助,鼓励作者写出更好的教程</a></p><h3>还可以分享给朋友</h3><p><wb:share-button appkey="1391944217" addition="full" type="button" ralateuid="1658384301" picture_search="false" pic="http://www.liaoxuefeng.com/files/attachments/001385348516246a18bd54b498f4c74b694624d67f02fa9000/l"><iframe src="./liaoxuefeng_files/share_social.html" width="312" height="62" frameborder="0" scrolling="no" marginheight="0"></iframe></wb:share-button></p><div style="width:336px;height:280px;float:left;"><a target="_blank" href="http://www.zhufengpeixun.cn/customize/node/index.html" onclick="_hmt.push(['_trackEvent', 'zhufeng', 'click', 'clicked']);"><img src="./liaoxuefeng_files/0(5)" style="width:336px;height:280px"></a></div><div style="width:336px;height:280px;float:left;"><a target="_blank" href="http://www.maizitime.com/pages/adpc/python.html?yy=lxfpy" onclick="_hmt.push(['_trackEvent', 'maiziedu', 'click', 'clicked']);"><img src="./liaoxuefeng_files/0(6)" style="width:336px;height:280px"></a></div><div style="width:336px;height:280px;float:left;"><a target="_blank" href="http://gold.xitu.io/welcome?utm_source=liaoxuefeng&utm_medium=banner&utm_content=gaoshou&utm_campaign=q3_personal" onclick="_hmt.push(['_trackEvent', 'xitu', 'click', 'clicked']);"><img src="./liaoxuefeng_files/0(7)" style="width:336px;height:280px"></a></div><div style="width:336px;height:280px;float:left;"><a target="_blank" href="https://www.julyedu.com/course/getDetail/51?source=lxf" onclick="_hmt.push(['_trackEvent', 'julyedu', 'click', 'clicked']);"><img src="./liaoxuefeng_files/0(8)" style="width:336px;height:280px"></a></div><div style="clear: both;"></div>
<hr>
<div id="x-wiki-prev-next" class="uk-clearfix uk-margin-left uk-margin-right"><div class="uk-clearfix uk-margin-left uk-margin-right"><span class="uk-float-left"><i class="uk-icon-chevron-left"></i> <a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000">版本回退</a></span><span class="uk-float-right"><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374829472990293f16b45df14f35b94b3e8a026220c5000">管理修改</a> <i class="uk-icon-chevron-right"></i></span></div></div>
<hr>
<div class="x-anchor"><a name="comments"></a></div>
<h3>评论</h3>
<ul id="x-comment-list" class="uk-comment-list"><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/0014647811605278434e211735948a78b7d644bb8fa917b000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/005IL8FDgw1eufw0vsa30j30go095gni.jpg" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00146802597247079be41f362624a39a4e5dd7ec3a7b66c000">git diff 和 git diff --cached 的理解</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/0014647811605278434e211735948a78b7d644bb8fa917b000">shulun_lv</a> created at 2016-7-9 8:59, Last updated at 2天前</div>
</div>
<div class="uk-comment-body x-auto-content">
<pre><code>git diff #是工作区(work dict)和暂存区(stage)的比较
</code></pre><pre><code>git diff --cached #是暂存区(stage)和分支(master)的比较
</code></pre><p>老师, 这样理解正确吗?</p>
</div>
</div>
<ul><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001383729881018b677b2776c24451e9b5f30a03ea5d73c000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001383729881018b677b2776c24451e9b5f30a03ea5d73c000">廖雪峰</a></div>
<div class="uk-comment-meta">Created at 2016-7-10 20:19, Last updated at 2016-7-10 20:19</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>正确</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001457860734665788c0546021f48288f273e89a586d83d000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(1)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001457860734665788c0546021f48288f273e89a586d83d000">tujide</a></div>
<div class="uk-comment-meta">Created at 2天前, Last updated at 2天前</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>如果说git diff是工作区跟暂存区的比较的话,那么将第一次修改的readme.txt文件add并commit后,根据廖老师上面说的图谱来看,暂存区应该是空的吧,我再次修改readme.txt文件后,执行git diff readme.txt,貌似没有跟空内容比较啊,是跟上一次的对比吧?</p>
</div>
</div>
</li>
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00146802597247079be41f362624a39a4e5dd7ec3a7b66c000"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00146802597247079be41f362624a39a4e5dd7ec3a7b66c000#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</ul></li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001486465495130a9b6c7d3712948a0a3f60401fbd566ab000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/8e38560ajw8evtxny14hyj20u00u0tbo.jpg" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/001486721198933729ba66db91943bb91f43580fbed5d7b000">执行最后一句</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001486465495130a9b6c7d3712948a0a3f60401fbd566ab000">谁给湖面画上云朵</a> created at 5天前, Last updated at 5天前</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>请向上滚动页面再看一次。好嘞~</p>
</div>
</div>
<ul>
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/001486721198933729ba66db91943bb91f43580fbed5d7b000"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/001486721198933729ba66db91943bb91f43580fbed5d7b000#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</ul></li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/00148626407261715ec3b7198f64c8484295e543fd2812e000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/default_avatar_male_50.gif" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014863471223223db956fb74504d5092a861fac43c2ddc000">挺好的教材</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/00148626407261715ec3b7198f64c8484295e543fd2812e000">啤酒醉虾</a> created at 2-6 10:12, Last updated at 2-6 10:12</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>学习了
git add
git status
git commit</p>
</div>
</div>
<ul>
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014863471223223db956fb74504d5092a861fac43c2ddc000"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014863471223223db956fb74504d5092a861fac43c2ddc000#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</ul></li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/0014623452570934e215a223a00431094ca073ed4563476000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(2)" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014623461495602465b53a171b4d99bd45eb458ddfe4d5000">概念解释</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/0014623452570934e215a223a00431094ca073ed4563476000">442空杯</a> created at 2016-5-4 15:15, Last updated at 2-2 1:19</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>这节版本库的概念,我理解的是.git文件夹就是版本库
《创建版本库》这节版本库的概念,我理解的是learngit目录就是版本库
不知道这样理解对不对</p>
</div>
</div>
<ul><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/0014623452570934e215a223a00431094ca073ed4563476000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(2)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/0014623452570934e215a223a00431094ca073ed4563476000">442空杯</a></div>
<div class="uk-comment-meta">Created at 2016-5-5 0:34, Last updated at 2016-5-5 0:34</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>哪位大神解释下,为什么廖老师讲了两个版本库概念?</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/0014859700688384d00daa29ecc4a57b9cc52da8d955f8f000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/530eb53bjw8ei88j2av5lj20hs0hsabs.jpg" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/0014859700688384d00daa29ecc4a57b9cc52da8d955f8f000">KingCO2</a></div>
<div class="uk-comment-meta">Created at 2-2 1:19, Last updated at 2-2 1:19</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>前者是git版本库,后者是你的工作区(Working Tree)</p>
</div>
</div>
</li>
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014623461495602465b53a171b4d99bd45eb458ddfe4d5000"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/0014623461495602465b53a171b4d99bd45eb458ddfe4d5000#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</ul></li><li>
<div class="x-anchor"><a name="COLLAPSE-1"></a></div><div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/00148533354555301a52b87c1444148bd2031a1ceafadbe000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/default_avatar_male_50.gif" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00148533310184862f883690a4c4786b75c52af74ed8251000">老师求解</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/00148533354555301a52b87c1444148bd2031a1ceafadbe000">平头哥_11542</a> created at 1-25 16:31, Last updated at 1-25 16:35</div>
</div>
<div class="uk-comment-body x-auto-content" style="max-height: 400px; overflow: hidden;">
<pre><code>Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: readme.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
license.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: readme.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
license.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
</code></pre><p>命令不起作用</p>
</div><p style="padding-left: 75px"><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000#0"><i class="uk-icon-chevron-down"></i> Read More</a><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000#0" style="display:none"><i class="uk-icon-chevron-up"></i> Collapse</a></p>
</div>
<ul><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/00148533354555301a52b87c1444148bd2031a1ceafadbe000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/default_avatar_male_50.gif" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/00148533354555301a52b87c1444148bd2031a1ceafadbe000">平头哥_11542</a></div>
<div class="uk-comment-meta">Created at 1-25 16:35, Last updated at 1-25 16:35</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>我找到原因了</p>
<pre><code>Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git add readme.txt
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git add license.txt
Administrator@10_141_10_68 MINGW64 ~/learngit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: license.txt
modified: readme.txt
</code></pre><p>应该这样才对</p>
</div>
</div>
</li>
<li>
<div class="x-comment-info">
<hr>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00148533310184862f883690a4c4786b75c52af74ed8251000"><i class="uk-icon-list-ul"></i> View Full Discuss</a>
<a target="_blank" class="uk-button uk-button-small" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00148533310184862f883690a4c4786b75c52af74ed8251000#reply"><i class="uk-icon-reply"></i> Reply This Topic</a>
</div>
</li>
</ul></li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001428974944198f4f8083d12364be59888ef2379a3a9e1000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(3)" width="50" height="50" alt=""></a>
<h4 class="uk-comment-title"><a target="_blank" href="http://www.liaoxuefeng.com/discuss/001409195939432748a2c9fae3846bc98b3c2a547fa321b000/00143936559210093b995b6af3e42b7b68e0addc2f1ebb9000">评论: 工作区和暂存区</a></h4>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001428974944198f4f8083d12364be59888ef2379a3a9e1000">z酱_</a> created at 2015-8-12 15:46, Last updated at 2016-12-8 21:52</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>暂存区的意义何在呢?
感觉比较麻烦啊, 每次commit之前还需要add一次</p>
</div>
</div>
<ul><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001428974944198f4f8083d12364be59888ef2379a3a9e1000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(3)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001428974944198f4f8083d12364be59888ef2379a3a9e1000">z酱_</a></div>
<div class="uk-comment-meta">Created at 2015-8-12 15:47, Last updated at 2015-8-12 15:47</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>如果我忘记add(这个文件之前已经add过)
直接commit会有什么情况出现呢</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001442803832148b0f4dc618ee74a368563930bec09e836000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/0(9)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001442803832148b0f4dc618ee74a368563930bec09e836000">新的开始爱自己</a></div>
<div class="uk-comment-meta">Created at 2015-9-21 10:49, Last updated at 2015-9-21 10:49</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>暂存区就是来确定你修改了哪些文件吧,修改过的文件放置到暂存区。等确定完哪些需要提交之后,再在暂存区一次性commit到分支里面。没有这个区域的话怎么知道哪些文件是修改过的?
个人理解</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001443846942348f1a461da9aab48adb55f4bc98a3dc442000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(4)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001443846942348f1a461da9aab48adb55f4bc98a3dc442000">oneMortale</a></div>
<div class="uk-comment-meta">Created at 2015-10-3 12:34, Last updated at 2015-10-3 12:34</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>这么理解呢,所谓暂存区是不是跟CoreData里的context差不多,是内存上适时分配的一部分空间。当你对源码做出修改后,git会基于之前的记录实时更新你的修改,但是如果你不进行commit,这些更改是不是被写入到硬盘里的。</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001443846942348f1a461da9aab48adb55f4bc98a3dc442000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(4)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001443846942348f1a461da9aab48adb55f4bc98a3dc442000">oneMortale</a></div>
<div class="uk-comment-meta">Created at 2015-10-3 12:44, Last updated at 2015-10-3 12:44</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>看完下一章的话,应该就是这样了吧,add 会提示git我们进行了修改,然后git会去找到修改的具体内容,找到的结果会放在暂存区,如果没有提示修改,git不会去查看这个文件,修改就会遗漏。这个暂存区是在硬盘上的还是内存上的不知道。</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/001446777008545fddce4ca874b46458867e87fe3ec2be2000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(5)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/001446777008545fddce4ca874b46458867e87fe3ec2be2000">sphenisciforme</a></div>
<div class="uk-comment-meta">Created at 2015-11-11 15:06, Last updated at 2015-11-11 15:06</div>
</div>
<div class="uk-comment-body x-auto-content">
<p>如果没有暂存区的概念,我们在容器中任意的修改commit的时候都会被加入到branch里,但是有可能我们添加一个临时文件,但是我们不想把它commit上去。</p>
</div>
</div>
</li><li>
<div class="uk-comment">
<div class="uk-comment-header" style="margin-bottom:0">
<a target="_blank" href="http://www.liaoxuefeng.com/user/00144885987762812bf9441a9dd46f69966aee04b6d8fa8000"><img class="uk-comment-avatar uk-border-circle x-avatar" src="./liaoxuefeng_files/1(6)" width="50" height="50" alt=""></a>
<div class="uk-comment-meta"><a target="_blank" href="http://www.liaoxuefeng.com/user/00144885987762812bf9441a9dd46f69966aee04b6d8fa8000">来撸一发吧</a></div>
<div class="uk-comment-meta">Created at 2015-11-30 13:02, Last updated at 2015-11-30 13:02</div>
</div>
<div class="uk-comment-body x-auto-content">
<p> **或许可以把它类比为内存缓冲区,add就类似于先在这个缓冲区里填入一些数据,然后commit就类似于一次性缓冲区里的数据写入硬盘,能提高效率。。。。个人理解,刚接触git,希望大神纠正错误,不要让我误导更小白的童鞋,哈哈。</p>
</div>
</div>