Reputation: 1064
In a view to remove big files from a GIT repository we had to change public history using BFG.
This implies that all developpers should clone it from scratch again to avoid pushing changes from the previous history.
Is there way to block the push from developper repo with non-fresh repo ?
Upvotes: 0
Views: 159
Reputation: 30966
Since not enough details are provided, I'll just give one possible solution.
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
Upvotes: 1
Reputation: 1228
I'm guessing any pushes would be forced pushes since the history changed. If that's true, you could block all force pushes using the solution mentioned here. It involves setting some configuration values on the central repository.
Upvotes: 0