0

How can I find the oldest commit in git?

I can find a lot of similar questions here, but most of them are actually asking to find the first commit. However, the first commit is not necessarily the oldest for a lot of reasons, you can have a commit cherry-picked from another repo, commit applied from a patch file, or maybe you have rebased in the past and reordered commits. In either case, the commits may not be in chronological order.

I would like to find the oldest commit as in having the oldest author-date or commit-date. How can I do that?

zypA13510
  • 1,092
  • 1
  • 10
  • 28
  • @caramba No, it does not. As I said, the question you linked to asked "earliest", but in both the question and the answers are actually about "first", because they seem to assume the first commit is always the earliest one. – zypA13510 Mar 02 '21 at 15:37
  • How can the earliest and the first be different? – CryptoFool Mar 02 '21 at 15:39
  • 3
    what about this [How can I make git log order based on author's timestamp?](https://stackoverflow.com/questions/8576503/how-can-i-make-git-log-order-based-on-authors-timestamp) – caramba Mar 02 '21 at 15:39
  • @CryptoFool I suggest you read this question. – zypA13510 Mar 02 '21 at 15:40
  • maybe ur looking for something like [this] (https://stackoverflow.com/questions/5188914/how-to-show-first-commit-by-git-log) – Wang Du Mar 02 '21 at 15:41
  • @caramba Ok, the 2nd one is actually what I'm looking for. Thanks. We can close it as a duplicate now. – zypA13510 Mar 02 '21 at 15:42
  • @user5532169 - My question is genuine, and I did read the question. I realize that commits don't have to be in chrono order. I'm thinking about just the first commit. A cherry pick creates a new commit. So does applying a patch. You can reorder certain kinds of commits, but you can't move a commit modifying a file to a position prior to the commit that added that file. Since there were no files in the repo prior to the first commit, I don't see how you could do a reorder such that some other commit would be moved before it. – CryptoFool Mar 02 '21 at 15:53
  • @CryptoFool 1) in the case of cherry-pick/patch, they can actually create a commit with author-date before the first commit in the repo, the commit could be purely adding a new file, not modifying an existing file 2) in the case of rebase, you can create a few commits, and then `git rebase -i --root`, and then reorder them in reverse (as long as it make sense, e.g. each commit only create new file and no modification), so now the last commit is actually the oldest. – zypA13510 Mar 02 '21 at 15:58
  • @user5532169 - ok, thanks – CryptoFool Mar 02 '21 at 16:08
  • @CryptoFool no problem. And sorry, I shouldn't have assumed you didn't read it in full. But maybe you could have asked with the details like you did later. – zypA13510 Mar 02 '21 at 16:13

0 Answers0