4

I am searching for a single git command(if possible) to checkout files from one repository at certain time(i.e. my local branch time).

Scenario: I have checked out Branch1 at a certain time, may be 2 days back(11/12/2015 19:05). I want to checkout another branch i.e. Branch2 of 2 days back(11/12/2015 29:05 i.e. 10 minutes after Branch1 checkout time).

How can I achieve this?

Instead of date I can use unix time stamp if its easier.

If I use "git log -1 --format=%ct" it will give me the time stamp. Then I can add 10 minutes to this timestamp and use below command to checkout.

git archive --format tar --remote <HUB>:<REPO> master:`dirname <FILEPATH>` | tar -xO <FILE> > log_file.git

Can it be possible in one command?

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
Pritish
  • 191
  • 1
  • 1
  • 7

1 Answers1

0

Git stores the time of each commit in the repository, but the storage within the repository is not BASED on the time the changes were made. The git repository data is structured based on the changes themselves.

You cannot rely on a repository to have every commit applied to the repository in chronological order. For instance, one could cherry-pick an older change from a different branch into the current branch and it's commit date would be preserved as the original, yet the date of the previous commit is later than this cherry-picked one.

Now, that was just for the sake of explanation. In your case, I trust that you know how you've committed changes to your repository. Still, git will not let you select based on time.

What I recommend is to use git log to find the commit from two days ago, then manually look at the history to find what changed ten minutes later.

When you find the hash of the revision that you are interested in, check it out into a new branch, like so:

git checkout <hash> -b newbranch
mkrufky
  • 3,268
  • 2
  • 17
  • 37
  • my requirement is to get the / timestamp of one repository and using the same timestamp value I want to execute the above git archive command. I want to checkout(git archive) some files from different repository from my local branch which has checked out code of another repository. This will be an automatic process, I want to execute these commands in C file using system() command. – Pritish Nov 12 '15 at 12:58
  • There are two dates associated with each commit: The author date and the commit date. In the case of a cherry-pick or rebase, the author date is the date of the original commit, and the commit date is the date of the cherry-pick or rebase. Commit dates are chronological (unless you play games like `--committer-date-is-author-date` or `GIT_COMMITTER_DATE`), and I suspect that's what the OP is after. – Raymond Chen Nov 12 '15 at 15:05