Source Control (4-8), Git - Get A Specific Version Or Commit in Practice

NoteThis is a series of articles related to Source Control. If you have read my other articles in this series, you may skip the top general part and jump to INTRODUCTION for the specific topic of this article.

This is a series of articles related to Source Control or Version Control issues, from a stand-alone app, such as MS SourceSafe, to a Server app, such as MS TFS (Team Foundation Server), to web services such as GitHub, AWS, and MS Azure DevOps. We have tried to categorize this series of articles as Source Control or Version Control, but this site does not have these categories. So, we put the articles in the DevOps category, as explained in the Wiki:

DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality.[1] DevOps is complementary to Agile software development; several DevOps aspects came from the Agile methodology.

The structure of this article series will cover:

  • Stand Alone App:
    • MS Source Safe
  • Server App
    • MS TFS (Team Foundation Server)
  • Online (Cloud) Centralized Service:
    • MS Azure: DevOps
      • Boards
      • Repos
      • Pipelines
      • Test Plans
      • Artifacts
    • GitHub
    • AWS GitHub Enterprise
  • Distributed App:
    • Git

Because these are huge topics, I will not go step by step. Instead, each section will be relatively independent and will become a reading unit.

A - Introduction

In the previous article, Source Control (4.7), Git --- Get Specific Version or Commit, we discussed the way for TFS to get the latest version and specific version for a Branch, we discussed the similarity and difference between Git and TFS, while Git is for similar concept to get a Branch and a specific Commit in a Branch.

Besides the concepts, in practice, we found out that by making a New Branch from the commit in View History might be the best way to get a Specific Version in Git. I will demonstrate this in this article.

The contents of this article:

  • A - Introduction
  • B - Make a New Branch from a Commit in a View History
  • C - Use Reset to Get the New Branch from a Commit in a View History

B - Make a New Branch from a Commit in a View History

In one project, I found out there is a long lasting bug. It is difficult to figure out the reason, then I tried to trace back and see where and when the bug started. At this point, I need to trace back the code history.

For the specific file, Right Click => Git => View History:

We got the History for this file:

In fact, I have worked on this file for a while, and have created several new Branches for my analyses, such as master_text1_1,  master_text1_2, ....... For demo purpose, I will create a new Branch master_text1_12 that has not existed yet.

Right Click the commit, 4e88e754, => New Branch:

In the Create a new branch window, type in a name, I made it as master_test1_12:

Create the new Branch, master_test1_12, it will be checking out automatically:

The new created branch, master_test1_12, will be shown in the file chosen history:

View the history of the new Branch, master_test1_12, its HEAD will point to the Commit: 4e88e754

Use this way, we can create the new Branches, as many as we need, against each commit that we need to test:

Note:

Because Git branches will occupy very small spaces, we can do that as we need (I remember I read this, but cannot find out the source right now),

C - Use Reset to Get the New Branch from a Commit in a View History

We tried a different way, using Reset, we will get the same result.

From the base Branch, say, master

Make a new Branch, master_test2:

The new branch is created:

Make a Hard Reset for the Commit: 4e88e754

View the history of the new Branch, master_test2, its HEAD will point to the Commit: 4e88e754, which is the same as we have in Branch master_test1_12

At this point, using Reset command, we can get exactly the same result as using New Branch, but with an extra step to create a New Branch from HEAD, instead of from the specific Commit, then Reset from the Commit. So, we should use the New Branch approach.

Reference


Similar Articles