Since not enough details are provided, I'll just give one possible solution.
- Find the oldest commit which is on the old branch but not on the new branch.
- Write a
pre-receive
hook in the remote repository. In this hook, you can get the tip of the pushed branch. If the oldest commit is reachable from the pushed branch, then prevent the push and echo why the push fails and how to solve the error.
For example if the old branch is A-B-C-D-E-F
and the new is A-B-C-M-N-O
, then D
is the oldest commit. If the new is A'-B'-C'-D'-E'-F'
, then A
is the oldest.
In the pre-receive
hook, you can get the tip like this:
#!/bin/bash
OLDEST=xxxx
while read old new name;do
#$new is the tip of the pushed branch
if git merge-base --is-ancestor $OLDEST $new;then
echo "Error: you are pushing commits with the old history."
echo "Error: please clone the repository with the new history."
exit 1
fi
done