Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebasing everyone onto changed git history after filter-branch

Tags:

git

Our git repo has a bunch of large files in its history that are no longer needed. I want to remove them using the filter-branch technique explained in Pro Git:

http://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery

I'll then use git push --force all to send this to our shared repo, as explained here:

Update a development team with rewritten Git repo history, removing big files

BUT. Pro Git says I'll need to have everyone rebase since I'm changing history. We've only sparingly used rebase, usually just as an alternative way to merge. I can have everyone re-clone, but that's a last resort; several devs have local branches with changes they'd like to keep.

So: What exactly will everyone need to do in our local repositories to rebase onto the newly-changed shared repo? And do we have to do it once per tracking branch? Our repo is referred to as origin and the master branch is master, if you want to give step-by-steps (and I'd love it if you would).

like image 792
Jay Levitt Avatar asked Sep 26 '11 22:09

Jay Levitt


People also ask

What is the golden rule of rebasing in git?

The Golden Rule of Rebasing reads: “Never rebase while you're on a public branch.” This way, no one else will be pushing other changes, and no commits that aren't in your local repo will exist on the remote branch.

Does git rebase remove history?

The history can be messed up using rebase, but normally remote repo will not accept the change that modifies the history (unless you use git push --force), but even more, the developer with push permission can delete the branch completely (git push origin :branch-name).

When should you avoid rebasing?

If you use pull requests as part of your code review process, you need to avoid using git rebase after creating the pull request. As soon as you make the pull request, other developers will be looking at your commits, which means that it's a public branch.

What does git filter branch do?

git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .


1 Answers

The key is for each individual developer not to lose their original reference to master until after they've done their rebase. To do this, have them do a fetch (not a pull) after the forced push, then for each local branch, do:

git rebase --onto origin/master master <local_branch>

When that's done, then they can checkout their master and update it by:

git pull --force
like image 190
Karl Bielefeldt Avatar answered Oct 13 '22 00:10

Karl Bielefeldt