How to archive a repo and copy the last n commits to a new one. republik/magazine
is used as an example here.
- Ìnstall git script
rebase-from
git config --global alias.rebase-from '!b="$(git branch --no-color | cut -c3-)" ; h="$(git rev-parse $b)" ; echo "Current branch: $b $h" ; c="$(git rev-parse $1)" ; echo "Recreating $b branch with initial commit $c ..." ; git checkout --orphan new-start $c ; git commit -C $c ; git rebase --onto new-start $c $b ; git branch -d new-start ; git reflog expire --expire=all ; git gc --prune=all'
- make a backup
mkdir backup
cd backup
git clone --mirror [email protected]:republik/magazine.git
cd ..
- clone
git clone [email protected]:republik/magazine.git
cd magazine
- Archive repo on github.
(Settings -> Danger Zone -> Archive this repository)
- Search and note for the latest commit to keep.
git log
.
177fa35c78730b7c687f8576f9501f847746eaad
- Rebase
git rebase-from 177fa35c78730b7c687f8576f9501f847746eaad
- Roll
- Rename repo on github
${name}-${yearStart}${monthStart}-${yearEnd}${monthEnd}
- Create new repo
${name}
- Add remote
new
:git remote add new [email protected]:republik/magazine.git
- Push
git push new geometric-blazing-skull
(name of main branch at the time)
- Tags
If present, also copy the meta
tag. In this example, the tag v945
was the latest version-name, applied to the latest commit. If you need to tag a previous commit with a version tag, just add the commit id after git tag -a vxxx
# note tag messages
git show v945
git tag -d v945
git tag -d publication
git tag -d prepublication
git tag -a v945 # insert message noted above
git tag publication v945
git tag prepublication v945
git push new v945
git push new publication
git push new prepublication
- Reindex repositories
heroku run "node packages/search/script/pullElasticsearch.js -i repo" -a republik-publikator-api
- Profit