Skip to content

Instantly share code, notes, and snippets.

@detunized
Last active November 26, 2021 08:41
Embed
What would you like to do?
Join repos into subfolders with flat history
#!/bin/bash
set -euo pipefail
$REPO_DIR=~/devel
repos="1password bitwarden dashlane lastpass opvault passwordbox roboform stickypassword truekey zoho-vault"
# pull all repos
(
for repo in $repos; do
echo $repo
cd $REPO_DIR/$repo
git pull -v --ff
done
)
# merge
(
rm -rf joined
mkdir joined
cd joined
git init .
for repo in $repos; do
git remote add $repo ~/devel/$repo-sharp
git fetch $repo
git checkout -b $repo $repo/master
echo -n "$repo: " > prefix
git filter-branch \
-f \
--tree-filter "mkdir -p .original/$repo && rsync -a --remove-source-files ./ .original/$repo/" \
--msg-filter "cat $(pwd)/prefix -" \
--env-filter 'GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' \
$repo
rm prefix
done
# create master
git checkout --orphan master
git rm -rf .
# cherry pick into the master
for i in $(git log --pretty='%H' --author-date-order --reverse $repos); do
GIT_COMMITTER_DATE=$(git log -1 --pretty='%at' $i) \
git cherry-pick $i
done
# cleanup
for repo in $repos; do
git branch -D $repo
git remote remove $repo
git update-ref -d refs/original/refs/heads/$repo
done
git gc --aggressive
)
@Schoaf
Copy link

Schoaf commented Apr 23, 2021

Why did you change line 25. I wanted to correct it but then I saw that you purposely changed that line. It just cannot work this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment