1
  1. Someone accidentally commited and pushed a number of large files
  2. I have deleted the files by using git-filter-repo that rewrites the history (like this answer suggests)
  3. The git-filter-repo --analyze has confirmed that the files are, in fact, removed
  4. I used git push --force to fore-push the rewritten history to the origin

So far so good

However

When the repo is pulled to other devs' machines (using git pull --rebase) the git-filter-repo --analyze still shows those big deleted blobs/files (not shown on my machine though)

git gc and git prune do not help.

What have I done wrong?

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
  • 2
    Colleagues need to fetch and `git reset —hard`. Any merge/rebase will not-remove those files from local commit history. There is very likely an existing question/answer that covers this - shall look for one. – AD7six Nov 10 '22 at 20:31
  • @AD7six I googled *a lot* before posting. Please post your comment as an answer, will upvote+accept – Alex from Jitbit Nov 10 '22 at 20:46
  • https://stackoverflow.com/q/4084868/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+recover+after+rebase – phd Nov 10 '22 at 20:49
  • Just ran `git reset —hard` - the files are still there – Alex from Jitbit Nov 10 '22 at 20:50
  • I also didn’t find one - it’s all about the search terms :). Phd to the rescue though – AD7six Nov 10 '22 at 20:50

1 Answers1

2

Fetch and reset hard

If a remote branch has changed and you want to match it exactly:

$ git fetch
$ git reset —-hard origin/main

If there are local commits they wish to keep that’s also possible using git rebase onto - for example to keep commits on feature-branch:

$ git fetch
$ git rebase --onto origin/main main feature-branch

Why didn’t rebasing just-work?

In the circumstances described in the question your colleagues have the unwanted files in their local clones - merging/rebasing the remote branch will not change that there are commits containing these unwanted files ( and any subsequent push will reintroduce those unwanted files to the remote).

AD7six
  • 63,116
  • 12
  • 91
  • 123