Como converter repositório Git de SHA1 para SHA256 e vice-versa

O truque básico é exportar um git bundle e então importá-lo novamente em um repositório recém-inicializado.

Note que o novo repositório não será compatível com o antigo - enquanto ele contém os mesmos commits, esta estratégia de migração não fornece nenhuma compatibilidade direta

Como migrar de repositório SHA1 para SHA256

git_bundle_migrate.sh
# Create new repo with SHA-256
git init --object-format=sha256 new-repo

# Move into old repo directory and create bundle
cd old-repo
git bundle create ../repo-bundle --all

# Move to new repo and unbundle
cd ../new-repo
git bundle unbundle ../repo-bundle

# Verify branches
git branch -a

Como migrar de repositório SHA256 para SHA1

git_bundle_migrate_back.sh
# Create new repo with SHA-1
git init --object-format=sha1 new-repo

# Move into old repo directory and create bundle
cd old-repo
git bundle create ../repo-bundle --all

# Move to new repo and unbundle
cd ../new-repo
git bundle unbundle ../repo-bundle

# Verify branches
git branch -a

Check out similar posts by category: Git