Joshua Fox
Joshua Fox

Reputation: 19675

How can I reconstruct the state of a Git branch at a given point in history?

Git does not store branch history, since a branch is just a kind moving label on a commit history.

But it is important for me to see whether certain code changes were pushed to master on a certain date. (The server got code on that date.)

What's the idiomatic way to do this?

Upvotes: 1

Views: 170

Answers (1)

AlBlue
AlBlue

Reputation: 24060

In general, you can't do this, by design. You can tell if a commit is on a branch, and you can tell when the commit was created, but you aren't necessarily going to be able to answer the question that you want to.

There are alternatives however, which may be of use.

  1. Use a git merge --no-ff when merging onto the master branch. That will create a merge node even if it's unnecessary from a DAG perspective. You can then encode in the git message that it's a merge to master, and that becomes your point of truth for later analysis.
  2. Use the git reflog to find out what the state of master was at any time. The reflog is normally time limited to 90 days, but that's tunable through the gc.reflogExpire option. You may want to disable explicit calls to this if you have access to the local repository.
  3. Use a different mechanism to trace your requirements. It seems that you want to know what master was on a given date so that you can determine what code was pushed on a given date. But there's going to be a difference between when code was pushed and when it was installed, unless you've got an automated pushing mechanism - in which case, use that to create your infinite log of requirements. Alternatively, the automated push should create an annotated tag, which allows you to verify what was pushed when and can include additional metadata such as the person who initiated the operation.

Upvotes: 3

Related Questions