0

As I recently tried to push my commits to github, I got the same error message as in this question. I removed the files from my repository but now have to clean up the history. As advised in the answers I looked into BFG, which seems to be the solution. While reading through the instructions it starts with using git --mirror link-to-remote-repo.

Now I am wondering, because I couldn't push the newest commit yet and probably my local commit history is longer than the one on github. Furthermore I am unsure as all the work I did is on a branch and not on master and how it affects my repository.

fukurai
  • 104
  • 1
  • 1
  • 9
  • What is a question? – Ivan Nov 28 '16 at 05:11
  • What I don't understand is that in order to use BFG I should do a bare clone (`--mirror`) of my remote repository. But this isn't up to date. So how is this going to work? I clean up the history of the remote mirror, but there is still "some history" about that file left in my local repository in the commits I did after the last time I pushed to github. – fukurai Nov 28 '16 at 05:25
  • Ok. In case you have not big number of changes (commits) you can do this manually: check out new branch on the base commit; For each commit (from problematic branch) - 1) use command `git cherry-pick --no-commit`; 2) delete from index problematic binary file (if exist); 3) commit – Ivan Nov 28 '16 at 05:29
  • Well, the branch is probably 16+ commits further than master/the last pushed commit on the remote. Which branch should I check out? The last one in the repository? – fukurai Nov 28 '16 at 06:46

1 Answers1

0

Manual solution (based on cheery pick)

EDIT: Before you start please commit or stash your local changes.

Let's say we have two branches master and dev which have common commit with SHA1 = X. Branch dev contains commits A1, A2, ..., A16

  • git checkout dev
  • git checkout -b new-dev
  • git reset --hard X

For each commit in dev (A1, ..., A16):

  • git cherry-pick A1 --no-commit
  • Check you index with git status
  • Remove your problematic binary files from the index git reset HEAD myfolder/mybinary.rpm
  • delete the file git rm myfolder/mybinary.rpm
Ivan
  • 3,084
  • 4
  • 21
  • 22
  • So just for me to understand, 1. I create a new branch `new-dev` and do `git reset --hard X` This discards all changes of any tracked file in `new-dev`. 2. I work through the commits in `dev` using `git cherry-pick` to remove the file as you described. Now I'm at my last commit. Do I merge first with `new-dev` and then with `master`? How do I get my repository back to the latest commit, just without the bad files? – fukurai Nov 29 '16 at 03:57
  • After you've done all steps you have new branch `new-dev` with the "same" history as in branch `dev` minus "bad" binary files. You should see the same number commits in `new-dev` as in `dev` with the same comments. So now you should merge `new-dev` to your `master`. Later, when you are really sure that all is correct you may delete `dev` branch. – Ivan Nov 29 '16 at 06:59
  • I see. But then I do `git cherry-pick` on `new-dev` and not on `dev`, or? – fukurai Nov 29 '16 at 08:05
  • Worked out. I could push the `new-dev` repository to github without any issues. Only thing I didn't expect was when I checkout out `new-dev` all the uncommited changes in `dev` were gone, even after I switched back to that branch. – fukurai Dec 07 '16 at 01:45
  • My mistake. `git reset --hard X` command delete all uncommitted changes. I'lll update the answer – Ivan Dec 07 '16 at 05:13