logoalt Hacker News

iamcoder18today at 3:45 PM10 repliesview on HN

This is cool, but has anyone ever needed to rewrite commit authors or dates?


Replies

simonwtoday at 4:20 PM

I've needed to do this for a bunch of reasons.

1. Sometimes I do a scraping project where I want the commit dates to match when the data actually changed, reconstructed from sources like the Internet Archive or the dates on https://platform.claude.com/docs/en/release-notes/system-pro... - for example here: https://github.com/simonw/research/commits/main/extract-syst... - or this project that attempted to reconstruct the history of Tim Berners-Lee's original browser: https://github.com/simonw/1991-WWW-NeXT-Implementation/commi...

2. Sometimes I split a Git repo into two, and I want to preserve the commit history (authors and dates) on the files that end up in the new repo - effectively replay the history of just one folder from the original to help create the new one.

3. I occasionally mess up cleaning up and merging a PR from an open source contributor such that the work is incorrectly credited to me. I'll fix the commit so that it credits the right person.

show 1 reply
xp84today at 3:57 PM

Yes, for instance it could be useful if someone’s been accidentally committing with a bogus email address. Or if you’re cleaning up some sort of mess and would like to recreate an accurate history.

Obviously as with any “force push” situation, the usual caveats apply if this is on a branch others have checked out, but if the mess is big enough, it is sometimes worth it to send everyone a script to reset or just to have people delete and re-check-out.

show 1 reply
ClikeXtoday at 7:37 PM

Very rarely. But it can come up if you archive change history in git for things that aren't originally tracked in git.

Take laws for example. Legalize[1] is a project that documents all laws into a git structure where each distinct change is a commit with the proper timestamp of tha change. Sure, this specific project builds that entire git history once and it's unlikely a retroactive change required such edits. But do something like this for historical sources where information is still coming in, and you might need to change a date when new findings occur.

[1] https://github.com/legalize-dev/legalize

gawstoday at 9:25 PM

> has anyone ever needed to rewrite commit authors or dates

Yes. Plenty of times.

f1shytoday at 4:02 PM

Yes. Absolutely! Many times I had a wrong configured terminal and messed up the author. Often I work in different projects, privately and in my work, and I use different authors for both

dgunaytoday at 5:22 PM

Times I have needed to do this:

  - An agent messed with my git config for some reason so I had to go back and fix the commit authorship
  - I created a PR mostly based on work that someone else did, so I reauthored most of the commits to be in their name
I have never personally needed to touch dates.
unqueuedtoday at 6:24 PM

The few times I've wanted to completely rearrange a repo, It's been enough just make a backup branch and then dump the log from there and pull what I want.

I have script somewhere I think it's called git-cherry-replace, which soft resets a commit id and copies the commit message and optionally populates GIT_COMMITTER_DATE and whatnot.

What I described is probably simple enough that an LLM can implement it.

But unless you're trying to retroactively reconstruct something to preserve the exact meaning, you should consider whether a rebase even makes sense.

icasetoday at 3:57 PM

yes; when i wanted to make it look like i didn’t procrastinate for a week and implement the entire feature in one day