Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: parent commit is younger than descendant?

Tags:

git

I was browsing http://arago-project.org/git/projects/linux-omap3.git repo and came across a strange date-thing, which basically says that parent commit is a year younger than its child.

How is this possible?

user@ubuntu1004:/f/linux-omap3$ git log -2 --parents  4b8db3b
commit 4b8db3b368f5601717e3ffee0051628ba33172d3 3c0eee3fe6a3a1c745379547c7e7c904aa64f6d5
Author: Kevin Hilman <[email protected]>
Date:   Fri Aug 20 11:19:52 2010 -0700

    OMAP: bus-level PM: enable use of runtime PM API for suspend/resume

    [...skipped...]

    Cc: Rajendra Nayak <[email protected]>
    Signed-off-by: Kevin Hilman <[email protected]>

commit 3c0eee3fe6a3a1c745379547c7e7c904aa64f6d5 65f42886e24be2197b1263f138eabf40c6774d00
Author: Linus Torvalds <[email protected]>
Date:   Tue Jan 4 16:50:19 2011 -0800

    Linux 2.6.37
like image 279
Igor S.K. Avatar asked Oct 17 '12 12:10

Igor S.K.


People also ask

How can I tell if one commit is a descendant of another commit?

git rev-list should be able to walk back from a commit, up until another if reachable. If the last commit displayed is the same than the first commit in the git rev-list command, then it is a commit reachable from the second commit.

What is the parent of a commit?

The parent commit is the commit this current commit is based on. Usually: When you git commit normally, the current commit becomes the parent commit of the new commit that's introduced by the command.

Can we change the parent branch in git?

We can create a new branch with parent master branch and use git cherry-pick command to move each commit from one branch to another. This solution is OK, when you don't have many commits, because for each commit you need to do git cherry-pick .

What is first parent in git?

Git "First Parent" meaning The parent that gets recorded first (in the commit object of the new commit) is considered the "first parent", while the other one is considered the "second parent". It is possible for a commit to have an arbitrary number of parents.


2 Answers

As mentioned in the comments:

  • you put any timestamp you want on a commit: "git commit - setting timestamps into the future"
  • you can amend the timestamp of a commit: "How can one change the timestamp of an old commit in Git?"
  • You are dealing with two dates: GIT_AUTHOR_DATE and GIT_COMMITER_DATE: See working with date in Git.

What you see could be the result of a:

  • rebase, since git rebase does actually not change authors' timestamps by default: see "git rebase without changing commit timestamps".
  • cherry-picking (as commented by Michael Anderson) since it also preserves GIT_AUTHOR_DATE
like image 130
VonC Avatar answered Oct 13 '22 22:10

VonC


The accepted answer is way more technically insightful, but I'll just add how this actually happened to me. I was debugging an issue that was affected by the local computer date, and was actively changing my system clock to track down the bug. After fixing it I committed everything to git unaware that my system clock was still set 2 months in the future, thereby screwing up my git history since I only noticed a few days later when commits showed up out of order in Github (d'oh!). This is supposedly fixable, though I haven't tried it yet.

like image 27
Brian Moeskau Avatar answered Oct 13 '22 22:10

Brian Moeskau