-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab_15.html
167 lines (160 loc) · 10.3 KB
/
lab_15.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
<!DOCTYPE html>
<html>
<head>
<title>Lab 15 - Git Immersion - Brought to you by EdgeCase</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" media="screen" href="screen.css">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1142510-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.hotkeys.js"></script>
<script type="text/javascript" src="UI.js"></script>
</head>
<body data-lab-id="15">
<div id="image_preloader">
<img src="green_circle_blur.png">
<img src="label_blur.png">
<img src="logo_small_blur.png">
<img src="prompt_blur.png">
<img src="pager_blur.png">
</div>
<header id="header">
<a href="index.html" id="home_link">Git Immersion</a>
<nav id="pager">
<a id="arrow_next" class="arrow" href="lab_16.html">Next</a>
<a id="arrow_previous" class="arrow" href="lab_14.html">Previous</a>
<a id="table_of_contents_link" href="#">Table of Contents</a>
<a id="bookmark_link"><span id="bookmark"></span>Bookmark this lab</a>
<a id="edgecase_link" href="http://edgecase.com" target="_blank">EdgeCase</a>
</nav>
<h1 class="lab_title"><em>lab 15</em> Undoing Staged Changes (before committing)</h1>
<a href="http://edgecase.com" target=_blank" id="other_edgecase_link">EdgeCase</a>
</header>
<div id="main_content">
<h1 class="lab_title"><em>lab 15</em> Undoing Staged Changes <br>(before committing)</h1>
<h3>Goals</h3>
<ul>
<li>Learn how to revert changes that have been staged</li>
</ul>
<h2>Change the file and stage the change <em>01</em></h2>
<p>Modify the <code>hello.rb</code> file to have a bad comment</p>
<h4>File: <em>hello.rb</em></h4>
<pre class="file"># This is an unwanted but staged comment
name = ARGV.first || "World"
puts "Hello, #{name}!"
</pre>
<p>And then go ahead and stage it.</p>
<h4>Execute:</h4>
<pre class="instructions">git add hello.rb</pre>
<h2>Check the Status <em>02</em></h2>
<p>Check the status of your unwanted change.</p>
<h4>Execute:</h4>
<pre class="instructions">git status</pre>
<h4>Output:</h4>
<pre class="sample">$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.rb
#
</pre>
<p>The status output shows that the change has been staged and is ready to be committed.</p>
<h2>Reset the Staging Area <em>03</em></h2>
<p>Fortunately the status output tells us exactly what we need to do to unstage the change.</p>
<h4>Execute:</h4>
<pre class="instructions">git reset HEAD hello.rb</pre>
<h4>Output:</h4>
<pre class="sample">$ git reset HEAD hello.rb
Unstaged changes after reset:
M hello.rb
</pre>
<p>The <code>reset</code> command resets the staging area to be whatever is in <span class="caps">HEAD</span>. This clears the staging area of the change we just staged.</p>
<p>The <code>reset</code> command (by default) doesn’t change the working directory. So the working directory still has the unwanted comment in it. We can use the <code>checkout</code> command of the previous lab to remove the unwanted change from the working directory.</p>
<h2>Checkout the Committed Version <em>04</em></h2>
<h4>Execute:</h4>
<pre class="instructions">git checkout hello.rb
git status</pre>
<h4>Output:</h4>
<pre class="sample">$ git status
# On branch master
nothing to commit (working directory clean)
</pre>
<p>And our working directory is clean once again.</p>
</div>
<div id="index">
<h1>Table of Contents</h1>
<div id="show_bookmarks"></div>
<div id="no_bookmarks"></div>
<ul>
<li id="lab_0_link"><a href="index.html"><span> </span>Home Cover Page</a></li>
<li id="lab_1_link" data-lab-id="1"><a href="lab_01.html"><span>1:</span> Setup</a></li>
<li id="lab_2_link" data-lab-id="2"><a href="lab_02.html"><span>2:</span> More Setup</a></li>
<li id="lab_3_link" data-lab-id="3"><a href="lab_03.html"><span>3:</span> Create a Project</a></li>
<li id="lab_4_link" data-lab-id="4"><a href="lab_04.html"><span>4:</span> Checking Status</a></li>
<li id="lab_5_link" data-lab-id="5"><a href="lab_05.html"><span>5:</span> Making Changes</a></li>
<li id="lab_6_link" data-lab-id="6"><a href="lab_06.html"><span>6:</span> Staging Changes</a></li>
<li id="lab_7_link" data-lab-id="7"><a href="lab_07.html"><span>7:</span> Staging and Committing</a></li>
<li id="lab_8_link" data-lab-id="8"><a href="lab_08.html"><span>8:</span> Committing Changes</a></li>
<li id="lab_9_link" data-lab-id="9"><a href="lab_09.html"><span>9:</span> Changes, not Files</a></li>
<li id="lab_10_link" data-lab-id="10"><a href="lab_10.html"><span>10:</span> History</a></li>
<li id="lab_11_link" data-lab-id="11"><a href="lab_11.html"><span>11:</span> Aliases</a></li>
<li id="lab_12_link" data-lab-id="12"><a href="lab_12.html"><span>12:</span> Getting Old Versions</a></li>
<li id="lab_13_link" data-lab-id="13"><a href="lab_13.html"><span>13:</span> Tagging versions</a></li>
<li id="lab_14_link" data-lab-id="14"><a href="lab_14.html"><span>14:</span> Undoing Local Changes (before staging)</a></li>
<li id="lab_15_link" data-lab-id="15"><a href="lab_15.html"><span>15:</span> Undoing Staged Changes (before committing)</a></li>
<li id="lab_16_link" data-lab-id="16"><a href="lab_16.html"><span>16:</span> Undoing Committed Changes</a></li>
<li id="lab_17_link" data-lab-id="17"><a href="lab_17.html"><span>17:</span> Removing Commits from a Branch</a></li>
<li id="lab_18_link" data-lab-id="18"><a href="lab_18.html"><span>18:</span> Remove the oops tag</a></li>
<li id="lab_19_link" data-lab-id="19"><a href="lab_19.html"><span>19:</span> Amending Commits</a></li>
<li id="lab_20_link" data-lab-id="20"><a href="lab_20.html"><span>20:</span> Moving Files</a></li>
<li id="lab_21_link" data-lab-id="21"><a href="lab_21.html"><span>21:</span> More Structure</a></li>
<li id="lab_22_link" data-lab-id="22"><a href="lab_22.html"><span>22:</span> Git Internals: The .git directory</a></li>
<li id="lab_23_link" data-lab-id="23"><a href="lab_23.html"><span>23:</span> Git Internals: Working directly with Git Objects</a></li>
<li id="lab_24_link" data-lab-id="24"><a href="lab_24.html"><span>24:</span> Creating a Branch</a></li>
<li id="lab_25_link" data-lab-id="25"><a href="lab_25.html"><span>25:</span> Navigating Branches</a></li>
<li id="lab_26_link" data-lab-id="26"><a href="lab_26.html"><span>26:</span> Changes in Master</a></li>
<li id="lab_27_link" data-lab-id="27"><a href="lab_27.html"><span>27:</span> Viewing Diverging Branches</a></li>
<li id="lab_28_link" data-lab-id="28"><a href="lab_28.html"><span>28:</span> Merging</a></li>
<li id="lab_29_link" data-lab-id="29"><a href="lab_29.html"><span>29:</span> Creating a Conflict</a></li>
<li id="lab_30_link" data-lab-id="30"><a href="lab_30.html"><span>30:</span> Resolving Conflicts</a></li>
<li id="lab_31_link" data-lab-id="31"><a href="lab_31.html"><span>31:</span> Rebasing VS Merging</a></li>
<li id="lab_32_link" data-lab-id="32"><a href="lab_32.html"><span>32:</span> Resetting the Greet Branch</a></li>
<li id="lab_33_link" data-lab-id="33"><a href="lab_33.html"><span>33:</span> Resetting the Master Branch</a></li>
<li id="lab_34_link" data-lab-id="34"><a href="lab_34.html"><span>34:</span> Rebasing</a></li>
<li id="lab_35_link" data-lab-id="35"><a href="lab_35.html"><span>35:</span> Merging Back to Master</a></li>
<li id="lab_36_link" data-lab-id="36"><a href="lab_36.html"><span>36:</span> Multiple Repositories</a></li>
<li id="lab_37_link" data-lab-id="37"><a href="lab_37.html"><span>37:</span> Cloning Repositories</a></li>
<li id="lab_38_link" data-lab-id="38"><a href="lab_38.html"><span>38:</span> Review the Cloned Repository</a></li>
<li id="lab_39_link" data-lab-id="39"><a href="lab_39.html"><span>39:</span> What is Origin?</a></li>
<li id="lab_40_link" data-lab-id="40"><a href="lab_40.html"><span>40:</span> Remote Branches</a></li>
<li id="lab_41_link" data-lab-id="41"><a href="lab_41.html"><span>41:</span> Change the Original Repository</a></li>
<li id="lab_42_link" data-lab-id="42"><a href="lab_42.html"><span>42:</span> Fetching Changes</a></li>
<li id="lab_43_link" data-lab-id="43"><a href="lab_43.html"><span>43:</span> Merging Pulled Changes</a></li>
<li id="lab_44_link" data-lab-id="44"><a href="lab_44.html"><span>44:</span> Pulling Changes</a></li>
<li id="lab_45_link" data-lab-id="45"><a href="lab_45.html"><span>45:</span> Adding a Tracking Branch</a></li>
<li id="lab_46_link" data-lab-id="46"><a href="lab_46.html"><span>46:</span> Bare Repositories</a></li>
<li id="lab_47_link" data-lab-id="47"><a href="lab_47.html"><span>47:</span> Adding a Remote Repository</a></li>
<li id="lab_48_link" data-lab-id="48"><a href="lab_48.html"><span>48:</span> Pushing a Change</a></li>
<li id="lab_49_link" data-lab-id="49"><a href="lab_49.html"><span>49:</span> Pulling Shared Changes</a></li>
<li id="lab_50_link" data-lab-id="50"><a href="lab_50.html"><span>50:</span> Hosting your Git Repositories</a></li>
<li id="lab_51_link" data-lab-id="51"><a href="lab_51.html"><span>51:</span> Sharing Repos</a></li>
<li id="lab_52_link" data-lab-id="52"><a href="lab_52.html"><span>52:</span> Advanced / Future Topics</a></li>
<li id="lab_53_link" data-lab-id="53"><a href="lab_53.html"><span>53:</span> Thank You</a></li>
</ul>
</div>
<div id="cover"></div>
</body>
</html>