Bertrand
Bertrand

Reputation: 1064

Force git clone after history change

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

Answers (2)

ElpieKay
ElpieKay

Reputation: 30966

Since not enough details are provided, I'll just give one possible solution.

  1. Find the oldest commit which is on the old branch but not on the new branch.
  2. 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

Upvotes: 1

Mike Gorski
Mike Gorski

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

Related Questions