2

I have a branch called add-ivp-solver that I have submitted as a PR for a project on GitHub. The branch has gotten a bit bloated and we now wish to move some of the files out of add-ivp-solver to a new branch called add-models which will be submitted as another PR in the future.

I would like to know if it is possible to move files and their associated commit history from add-ivp-solver to add-models in a way that will allow us to cleaning merge add-ivp-solver into master and close the original PR.

I think that git filter-branch might be what I need. This should allow me to remove the files and commit history from add-ivp-solver to add-models, but I am concerned that it will leave add-ivp-solver in an "inconsistent state" which will make it nearly impossible to merge and close the PR.

davidrpugh
  • 3,603
  • 1
  • 27
  • 40

1 Answers1

1

I am concerned that it will leave add-ivp-solver in an "inconsistent state" which will make it nearly impossible to merge and close the PR.

No, it will leave that branch with a different history, which means:

  • you will need to force push it to your fork

    git checkout add-ivp-solver
    // do your filter-branch
    git push --force origin add-ivp-solver
    
  • the PR will automatically adjust in order to take into account that new history (nothing to do)

  • the maintainer of the original repo can test again the merge of that PR
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • I created a new branch off of add-ivp-solver for testing the filter-branch. This new testing-branch is now exactly how I want add-ivp-solver to look. Should I now checkout add-ivp-solver and re-run the filter-branch? Or is there a way to reset the add-ivp-branch to the testing-branch? – davidrpugh Aug 26 '14 at 14:42
  • @davidrpugh if you are in the new `testing-branch` branch (checked out), you can do: `git branch -f add-ivp-solver testing-branch`, then `git checkout add-ivp-solver` will reference the same HEAD as `testing-branch` – VonC Aug 26 '14 at 15:08
  • VonC I am one of the maintainers of the original repo. The PR is [here](https://github.com/jstac/quant-econ/pull/23). The master branch of this repo has only 308 commits. This PR has about 150 unique commits (at least it showed about that before we tried re-writing history). When I merge the branch into my local master I end up with 887 commits. I think whatever we have done here re-wrote all original commits to the repo so they each appear twice now. I don't want two copies of the original history. Do you have any suggestions? – spencerlyon2 Aug 27 '14 at 19:58
  • @spencerlyon2 if you merge any PR which doesn't apply cleanly, drop it: the one making the PR has to fix it, not you. To fix it, the PR creator has to fetch from the original "upstream" repo (the one that was forked), and rebase `davidrpugh:add-ivp-solver` branch on top of the updated `master`. As in http://stackoverflow.com/a/3903835/6309. Or http://stackoverflow.com/a/16199389/6309. – VonC Aug 27 '14 at 20:07