user1393881
user1393881

Reputation:

why some git commits are older than their parent?

I was looking at apache-drill commit 3efc2eca and I realized that it is older than its parent commit 8614bae.

I have had a couple of other similar observations. How can I explain them?

Upvotes: 2

Views: 187

Answers (2)

vhula
vhula

Reputation: 497

You can change git history with an interactive rebase, e.g.:

git rebase --interactive|-i HEAD~(number of commits)

Here is the scenario:

$ git commit -m 'Commit 1'
$ git commit -m 'Commit 2'
$ git rebase -i HEAD~2
  // changing only 'Commit 1'
  edit bae2ea4 Commit 1
  pick 0e25612 Commit 2
$ git add .
$ git commit --amend
$ git rebase --continue

After these 'Commit 2' will be older than its parent 'Commit 1'

You should remember that you are not advised to rewrite history after your changes were published (pushed).

Upvotes: 2

Commit history in git is rewritable. There are many ways that that could have happened. The most likely way is that the commit was rebased after it was created.

Upvotes: 4

Related Questions