ZijingWu ZijingWu - 4 months ago 13
Git Question

How to get the snapshot of code with an commit number but forget the branch after merges?

We are maintain an code base using git. But have following branchs:


  1. master

  2. release_branch_1

  3. release_branch_2



we regularly merge those three branchs. But after an year we need to investigate an bug, we can find the git change number
941504fd85b0fede0675b1e934df1aa4763a0390
.

But seams all three branch contains this change, and we forget which branch we build the binary from.

So is it possible to get the snapshot of the code at that time point? Is the
{commit number}
unique identity the snapshot or
{branch + commit number}
pair unique identify the sanpshot?

Answer

Is the {commit number} unique identity the snapshot or {branch + commit number} pair unique identify the snapshot?

The former: to get a snapshot at that commit number, simply checkout your repo at that commit:

git checkout  941504fd85b0fede0675b1e934df1aa4763a0390

Branches can evolve, being renamed or deleted, but the commits are immutable.


If your bug investigation leads you to make some commit, it is best to checkout that commit with an associated branch, as hlovdal comments below:

git checkout -b my_snapshot 941504fd85b0fede0675b1e934df1aa4763a0390

Or, if you already checked out the commit directly (and are in a detached HEAD):

git branch my_snapshot 941504fd85b0fede0675b1e934df1aa4763a0390
Comments