7

7Regression with Brackets

7.3

Regressing with Checkout

I can’t stress strongly enough, if you want to look at an ear­lier com­mit point do it with the check­out func­tion.

I’m going to start from the same point I used for the reset in the pre­vi­ous sec­tion:

Figure 7.16 - Final arrangement, all merged back to master branch

Figure 7.16   Final arrangement, all merged back to master branch

There is a sin­gle mas­ter branch with eight com­mits and the head is at the most re­cent com­mit, in my case [07fe437]. In Brack­ets, the his­tory is:

Figure 7.17 - Brackets commit history

Figure 7.17   Brackets commit history

And we have the fol­low­ing files:

LIST OF FILES AT COMMIT 07FE437   TAG: P03

index.html

01-intro.html

02-about.html

README.md

.gitignore

11-resources\01-css\style.css

11-resources\02-images\logo.png

11-resources\02-images\readme.png

Table 7.3   File list at commit point P03 [07FE437]

Fi­nally, Git is re­port­ing:

Noth­ing to com­mit, work­ing di­rec­tory clean

So let’s do a check­out, again I’m going back to the first P01 com­mit point, [25c1410] in my list.

To do this, open the com­mit his­tory (Fig­ure 7.17) and click any­where on the P01 com­mit line [25c1410]. This will open the com­mit in­for­ma­tion screen:

Figure 7.18 - P01 commit point information screen

Figure 7.18   P01 commit point information screen

This time click the check­out but­ton checkout icon. This will open the check­out warn­ing di­a­logue box:

Figure 7.19 - Checkout function warning

Figure 7.19   Checkout function warning

This is telling us that the pro­ject is going into a de­tached head state and that we can’t make any fur­ther com­mits. This is ok, we don’t want to make any com­mits—we just want to have a look. Click ok.

Open the com­mit his­tory, and let’s see what we have:

Figure 7.20 - PCommit history after the checkout

Figure 7.20   Commit history after the checkout

Right, things are a bit dif­fer­ent this time. We have just the two com­mit points (D01 and P01) ex­actly as we had with the reset, but this time we are not on the mas­ter branch.

We are now on a branch called 25c1410. The mas­ter branch is still there, click the down arrow next to the 25c1410 branch and you will see it:

Figure 7.21 - Branches present after a checkout

Figure 7.21   Branches present after a checkout

We could switch back to it, and we will; but first let’s look around.

The files have changed to match the ear­lier com­mit point (just like with the reset); we now have these files:

LIST OF FILES AT COMMIT 07FE437   TAG: P03

index.html

README.md

.gitignore

11-resources\01-css\style.css

11-resources\02-images\logo.png

11-resources\02-images\readme.png

Table 7.4  File list after reset to P01 [25c1410]

These files have dis­ap­peared:

01-intro.html

02-about.html

Again if we were to look in­side the lab-01-web­site folder with Win­dows Ex­plorer we would only see index.​html, README.md and .git­ig­nore.

Just like it was with the reset.

Figure 7.22 - The working directory after the checkout

Figure 7.22   The working directory after the checkout

So, the pro­ject has moved back in time to the ear­lier com­mit points in ex­actly the same way as it did with the reset and if I opened any of the pro­ject files, they would be ex­actly as they were at the time of the [25c1410] com­mit.

The best prac­tice ap­proach to re­set­ting (§ 2.5.4), is that if we want to re­in­state the files at an ear­lier com­mit, we copy any or all of the files from this checked out com­mit point and, after mov­ing back (as in back to the fu­ture) to the most re­cent com­mit point, paste them into the work­ing area and make a new com­mit with the old files from the ear­lier com­mit (i.e. re­place the most up to date files with older files).

This, if you re­mem­ber is where the reset fell down, we couldn’t eas­ily get back to the most re­cent com­mit point (there was a lot of mess­ing about with the com­mand line).

Things are much eas­ier with the check­out func­tion.

The most re­cent com­mit point (in my case [07fe437]) is the head of the mas­ter branch. To get back, just switch to the mas­ter branch.

Click the arrow next to the 25c1410 branch and in the drop­down click mas­ter:

Figure 7.23 - Change branch present after a checkout

Figure 7.23   Change branch present after a checkout

This in­stantly takes us back to where we were; open the com­mit his­tory and every­thing is back where it was—easy:

Figure 7.24 - Returning to the most recent commit

Figure 7.24   Returning to the most recent commit

This time if you click the arrow next to the mas­ter branch, there will not be any other branches listed, the 25c1410 branch has dis­ap­peared.

The 25c1410 branch that was cre­ated by the check­out is just a tem­po­rary branch—it dis­ap­pears when we switch off it to any other branch.

The check­out is a much bet­ter way of view­ing ear­lier com­mits.

ONLY EVER USE THE CHECKOUT FUNCTION
TO ACCESS PREVIOUS COMMITS



End flourish image