rtyley / bfg-repo-cleaner

Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala
https://rtyley.github.io/bfg-repo-cleaner/
GNU General Public License v3.0
10.86k stars 535 forks source link

Rejected refs on git push #350

Closed aarnaut closed 4 years ago

aarnaut commented 4 years ago

Hey,

I know a similar question has already been asked, but none of the solutions seem to work for me. I have a repository hosted on an internal company Bitbucket server and I'm trying to clean up some old binaries that take up a lot of space. I'm trying to do the following:

git push fails with the following message:

remote: You are attempting to update refs that are reserved for Bitbucket's pull request functionality. Bitbucket manages these refs automatically, and they may not be updated by users.
remote: Rejected refs:
remote:         refs/pull-requests/1017/from
remote:         refs/pull-requests/1017/merge
remote:         refs/pull-requests/1021/from
remote:         refs/pull-requests/1021/merge
remote:         refs/pull-requests/1053/from
remote:         refs/pull-requests/1053/merge
remote:         refs/pull-requests/1070/from
remote:         refs/pull-requests/1079/from
remote:         refs/pull-requests/1080/from
...
remote:
To repo.git
 ! [remote rejected]       refs/pull-requests/1017/from (pre-receive hook declined)
 ! [remote rejected]       refs/pull-requests/1017/merge (pre-receive hook declined)
 ! [remote rejected]       refs/pull-requests/1021/from (pre-receive hook declined)
 ! [remote rejected]       refs/pull-requests/1021/merge (pre-receive hook declined)
 ! [remote rejected]       refs/pull-requests/1053/from (pre-receive hook declined)
 ! [remote rejected]       refs/pull-requests/1053/merge (pre-receive hook declined)
...

I've tried a couple of solutions, for example:

  1. After git clone --mirror repo.git, run git show-ref | cut -d ' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d and then git push after that. It fails with the same error.
  2. I tried following this guide: http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html. After git clone --mirror repo.git, I do git config -e, update the fetch config and finish off with git remote update and git push. This doesn't seem to do anything. I just end up getting the same error after running bfg. I'm not sure if this is expected, but my refs folder doesn't contain a pull-requests folder until I run bfg.
javabrett commented 4 years ago
  1. PRs will always reference un-rewritten history and trees, which will contain the old bulk.
  2. Bitbucket assumes that hidden PR refs should be read only.

You need to find a way to either override that fire Bitbucket, or delete the PRs and their refs, or push your cleaned repo to a fresh project, discarding the PRs.

aarnaut commented 4 years ago

I decided to do a push all refs except for PR, like this git push --force refs/head/* and git push --force refs/tags/*. This turned out fine.

johnpankowicz commented 2 years ago

Someone please correct me if I'm wrong, but I believe the solution by @aarnaut just hides the problem.

Question: Will (or could) these pull-requests eventually be removed by Github?

I experimented with a small test repo I added a file, "ngfile.txt", removed it and ran BFG to remove it from the history. I can still see the contents of the file when I look at the PR. But the PR info also telling me: "This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository." See PR info

Does this mean that the commit for the PR may eventually be removed during clean up?