0

I wanted to use git filter-branch to rewrite each commit or SHA1 message history with a different author and committer's date, e-mail, and name, but I've been warned against this usage and encouraged to use git-filter-repo instead. I used this command, and it created backups, and I am prevented of rewriting the history. I used -f, but it informed that the reference is unchanged.

I have read Changing author/committer(/tagger?) information . The question Git: Bulk change of commit dates answer isn't efficient. I also have seen https://stackoverflow.com/a/61368365/8041366 answer but it isn't efficient either.

But the documentation does not explain how to detect the commit or SHA1 message to change the author and committer's date, e-mail and name.

Of course, that this documentation warned me and recommended me to use git rebase, but I hate git base because it forces me to enter the text editor and to write edit with author and committer's date, e-mail, and name. It consumes a lot of time. I prefer automatic Shell script.

Analyse my automatic Shell script (file choose-sha1-message comes from https://stackoverflow.com/a/64044273/8041366):

#!/bin/sh

export TERM="linux"
export DIALOGRC="scripts/dialogrc"

source choose-sha1-message

sha="$(gsha)"

echo "Choose your complete GitHub or GitLab name"
read name

echo "Choose your GitHUb or GitLab e-mail:"
read email

echo "Choose your date (YYYY-MM-DD or YYYY/MM/DD):"
read ddate

echo "Choose your 24h hour (HH:mm:ss):"
read hour

echo "Choose your time zone:"
echo "For example, if you are from New York, then it is -0400, if from Paris, then +0100."
read zone

git filter-branch --env-filter \
'if [ $GIT_COMMIT = "$sha" ]
   then
      export GIT_AUTHOR_DATE="$ddate $hour $zone"
      export GIT_AUTHOR_EMAIL="$email"
      export GIT_AUTHOR_NAME="$name"
      export GIT_COMMITTER_DATE="$ddate $hour $zone"
      export GIT_COMMITTER_EMAIL="$email"
      export GIT_COMMITTER_NAME="$name"
fi' $sha
Oo'-
  • 203
  • 6
  • 22
  • 1
    You literally *cannot* change existing commits, and neither filter-branch nor filter-repo try to do that. They make *new* commits. The new repository is a *different repository*. In both cases you must throw away the old repository and use the new one instead. The key difference between filter-branch and filter-repo is that with filter-branch, you have to understand this; with filter-repo, the command doesn't let you misunderstand. – torek Sep 02 '22 at 08:19
  • Actually, I wanted to rewrite some commits with old dates (it will be always 2022, but I need to change the day, the month, and the time) instead of with new dates. I understand you'll say it is totally discouraged, but I saw they managed to rewrite some Unix repositories commits to 53 years ago: https://github.com/dspinellis/unix-history-repo. – Oo'- Sep 02 '22 at 14:15
  • Both filter-branch and filter-repo can replace the author and committer dates while they're doing the wholesale commit replacement work. This too results in new hash IDs and hence an incompatible repository. There's nothing wrong with doing it, you just need to know that this is what you're doing. – torek Sep 02 '22 at 22:30
  • Remember that at the most basic level, the operations consist of: read existing commit (turning it into modifiable data), modify it, write result out as new (immutable) commit. The rest is merely *careful arrangement* since each later commit holds the hash ID(s) of some earlier commit(s), and these hash IDs must also be replaced as part of the ongoing transformation. Any commit that, in the final result, comes out bit-for-bit identical to its original, keeps its original ID, but if you change the root commit, every descendant must change. – torek Sep 02 '22 at 22:33

0 Answers0