Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Why is git author date different from commit one?

cherry-pick

1.sh:

#!/bin/sh -eux
rm -rf 1
mkdir 1
cd 1
git init

echo 1 > 1
git add 1
git commit -m c1

git checkout -b dev
echo 2 > 2
git add 2
git commit -m c2
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'
c2=`git rev-parse HEAD`

sleep 1
git checkout master
git cherry-pick "$c2"
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'
$ ./1.sh
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: 78adc43
author date: Thu May 14 03:35:31 2020 +0300
commit date: Thu May 14 03:35:31 2020 +0300
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: ab3650b
author date: Thu May 14 03:35:31 2020 +0300
commit date: Thu May 14 03:35:32 2020 +0300

commit was reworded

1.sh:

#!/bin/sh -eux
rm -rf 1
mkdir 1
cd 1
git init

echo 1 > 1
git add 1
git commit -m c1
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'

sleep 1
GIT_SEQUENCE_EDITOR="sed -i '1s/pick/reword/'" \
    EDITOR="sed -i '1s/.*/c1 (changed)/'" \
    git rebase -i --root
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'
$ ./1.sh
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: b617d46
author date: Thu May 14 03:37:33 2020 +0300
commit date: Thu May 14 03:37:33 2020 +0300
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: 7f09598
author date: Thu May 14 03:37:33 2020 +0300
commit date: Thu May 14 03:37:34 2020 +0300

commit was changed

1.sh:

#!/bin/sh -eux
rm -rf 1
mkdir 1
cd 1
git init

echo 1 > 1
git add 1
git commit -m c1
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'

sleep 1
echo 2 > 2
git add 2
git commit -m c2
GIT_SEQUENCE_EDITOR="sed -i '2s/pick/fixup/'" \
    git rebase -i --root
git show --format='hash: %h%nauthor date: %ad%ncommit date: %cd'
$ ./1.sh
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: 0f2ad21
author date: Thu May 14 03:39:45 2020 +0300
commit date: Thu May 14 03:39:45 2020 +0300
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: cf2ceff
author date: Thu May 14 03:39:45 2020 +0300
commit date: Thu May 14 03:39:46 2020 +0300

parent commit was changed

1.sh:

#!/bin/sh -eux
rm -rf 1
mkdir 1
cd 1
git init

echo 1 > 1
git add 1
git commit -m c1

echo 2 > 2
git add 2
git commit -m c2
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'

sleep 1
GIT_SEQUENCE_EDITOR="sed -i '1s/pick/reword/'" \
    EDITOR="sed -i '1s/.*/c1 (changed)/'" \
    git rebase -i --root
git show -s --format='hash: %h%nauthor date: %ad%ncommit date: %cd'
$ ./1.sh
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: 46b4e22
author date: Thu May 14 03:40:44 2020 +0300
commit date: Thu May 14 03:40:44 2020 +0300
...
+ git show -s '--format=hash: %h%nauthor date: %ad%ncommit date: %cd'
hash: de91c32
author date: Thu May 14 03:40:44 2020 +0300
commit date: Thu May 14 03:40:45 2020 +0300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment