git reset --hard <SHA of the commit that you want to be the new latest commit>
To make the local branch identical to the “upstream”
git reset --hard @{u}
From git log
, determine the merge to be revert
git log
...
commit <hash of the merge commit>
Merge: <hash 1> <hash 2>
...
Usually, the <hash 1> is on the target branch, and <hash 2> is on the source branch
To revert the merge commit and come back to commit <hash 1>
git revert -m 1 <hash of the merge commit>
Asumming source code is cloned as:
/repositories/
repo-1
repo-2
cd /repositories
# NOTE: before doing this, decide the name for the new repository
# In this example, the name is merged-repo
mkdir merged-repo
cd merged-repo
git init
# push the whole repo-1 to the merge-repo
cd ../repo-1
git remote add merged-repo file:///repositories/merged-repo/.git
git push merged-repo
cd ../merged-repo
git checkout develop
# Move all code of repo-1 to a dedicated folder
mkdir repo-1
ls -a
# move all files/foldes (EXCEPT folder .git) to folder repo-1
git mv .gitignore repo-1
...
git add .
git commit -m "move source file of repo-1 into a dedicated folder"
# merge repo-2
git remote add repo-2 file:///repositories/repo-2/.git
git fetch repo-2
git merge --allow-unrelated-histories repo-2/develop
# push the merged repo to central repo
git remote add origin <url of the new central repo>
git push origin
# Install BFG (https://rtyley.github.io/bfg-repo-cleaner/)
# MacOS
brew install bfg
# install git LFS
brew install git-lfs
# clone the existing repository as a BARE one
git clone --mirror ...
# run bfg with --convert-to-git-lfs for a certain file (with name only) or file name wildcard
# TIP, to list all large files, use the following command
# for example >5MB: find ./ -type f -size +5000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
bfg --no-blob-protection --convert-to-git-lfs "{*.weights,*.mp4,*.dll,*.docx,*.exe,*.zip,*.doc,*.xlsx,filename-1,filename2}"
# cleanup
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# init LFS support for the repo
git lfs install
# if pushing to a new repo, change "remote"
git push --force