Find a date for a non-dated commit?

I am doing a git log to list all the commits and then parse them. With this command:

git log --encoding=UTF-8 --date=local --pretty=format:'%H,%P,%at,%ct,%an,%s' 

In some strange repositories, I get commits without a date both in the author's date and in commits. I tried with a simple:

 git log 

and I got the date of 1970.

The repo where this happens is SamWM / jQuery-Plugins , for example in commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 .

Although on GitHub we have an interesting date when we search for it.

Can someone help me get an interesting date for this commit, which should be somewhere in the middle of the others?

+6
source share
1 answer

git show --format=raw shows:

  commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48
 tree d63aeb159635cb231e191505a95a129a3b4a7b38
 parent 9276202f1c0dcc360433df222c90f7874558f072
 author SamWM < sam@webmonkeysolutions.com > 1288370243 --700
 committer SamWM < sam@webmonkeysolutions.com > 1288370243 --700

The time zone information is invalid here, and I'm not sure how the author created it. Other commits use the correct -0700 format.

You can convert this using the GNU date, bearing in mind that --700 should be -0700 :

  $ TZ = Etc / GMT + 7 date -d @ 1288370243
 Fri 29 Oct 09:37:23 GMT + 7 2010

therefore the correct answer in Git is the usual format Fri 29 Oct 09:37:23 2010 -0700 .

Note. I use TZ=Etc/GMT+7 , not GMT-7 . You can see by running the same command with different commits that have the correct time zone information that the result is exactly what it should have been. date changing the time zone is definitely the wrong way for what is needed here, and by denying the offset, I cancel the error.

You can fix such commits in a local copy with git hash-object and git replace . Firstly, a health check that my commands are fine:

  $ git cat-file commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 |
 > git hash-object -t commit -w --stdin
 e9dddaf24c9de45d9b4efdf38eff7c30eb200f48

This command downloaded the specified commit, wrote it unchanged, and showed the rewritten hash code. I use this as a sanity check: if I had a different hash, something in my team would be a mistake.

Now you can insert something to create a fixed commit:

  $ git cat-file commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 |
 > sed -e 's / - 700 / -0700 /' |
 > git hash-object -t commit -w --stdin
 46694249ed3d519b0c934222520b9dc6d8557fa1

and use a fixed commit instead:

  $ git replace e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 46694249ed3d519b0c934222520b9dc6d8557fa1

After that, all references to e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 will look instead of 46694249ed3d519b0c934222520b9dc6d8557fa1 , and git show e9dddaf24c9de45d9b4efdf38eff7c30eb200f48 now starts with:

  commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48
 Author: SamWM < sam@webmonkeysolutions.com >
 Date: Fri Oct 29 09:37:23 2010 -0700

     Update version number, make text formatting and indentation consistent with the rest of the code
+4
source

Source: https://habr.com/ru/post/969660/


All Articles