1

I discovered that my .gitignore file was not commited into my git repository at all. I have about 300 commits in my repository with a few branches I made: I am using the git flow model so now I have master, develop and a few feature branches

I do not care how but I want to amend the first commit somehow and all versions after it.

as i see it i have two options:

  1. add the .gitignore as new commit before the 1st commit containing only the .gitignore file.
  2. amend the first commit somehow

I tried option #1 using this link but on rebase I get this error

$ git rebase --onto newroot --root master
First, rewinding head to replay your work on top of it...
Applying: First Commit
fatal: Out of memory, realloc failed
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 First Commit
The copy of the patch that failed is found in:
   c:/Temp/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

my biggest file is about 40MB and the whole project size is about 1.6GB. when I ran this command I closed everything running and had about 10GB of free memory (I have 16GB in total).

any ideas how to do this?

Community
  • 1
  • 1
Dani Avni
  • 423
  • 5
  • 14
  • 1
    Why just not trying to fix the existing repo? Removing unwanted files, etc. – Robert Dec 17 '13 at 14:26
  • I need to add a new file. what file removal are you referring to? – Dani Avni Dec 17 '13 at 14:56
  • I got it. So, do you really need that file in the first commit? Why not just only adding it to the current upstream? – Robert Dec 17 '13 at 15:28
  • I prefer it in the first commit just incase someone checks out an historic branch. this way my colleagues will not commit unneeded files into our repository. on a side note, all my colleagues have no current open branches in their local repositories. when I finish this rebase, the new repository will be uploaded to our server and pulled down as a new repository where needed – Dani Avni Dec 17 '13 at 15:48

2 Answers2

1

Have you tried interactive rebase?

$ git rebase -i --root

Then put "edit" in first commit. There add your new file, then git rebase --continue, and it will do what you need.

Robert
  • 33,429
  • 8
  • 90
  • 94
  • I tried it just now and after fast crash course in VIM (I use sourcetree on windows) I selected to edit the first commit. I added gitignore using "git add .gitignore" and then did "git commit --amend" and then "git rebase --continue". rebasing started to count up but then I got an error "error: could not apply 6e2870c... reformat web.config". this specific commit is in a feature branch merged into develop branch on July. what could be the problem? – Dani Avni Dec 17 '13 at 15:43
  • Rebase flattens out merges. You can use `-p` to preserve merges but that can interact badly with interactive rebase and editing (see the documentation). I *think* you'll be OK if you're just amending the root commit, but you may want `git filter-branch` rather than rebase. – torek Dec 17 '13 at 17:44
  • torek, do you have some sample on how to add a file to the first commit or add a new commit as the first using 'git filter-branch' ? – Dani Avni Dec 18 '13 at 08:03
0

I didn't realize git needed increasing levels of memory for long rebases. Interesting.

You could do the rebase in phases. You don't have to give it master as the target. You could give it a commit halfway along the branch, or 1/3rd of the way. That won't move the master tag at the end, so you'll have to drop a tag or temp branch name on it, but then you can rebase onto that with the next bit, and do it all in stages that your memory can handle. At the end you can git reset --hard to move master to the new branch.

Gary Fixler
  • 5,632
  • 2
  • 23
  • 39
  • it looks to me like the failing rebase is on the very first commit which was the entire 1.6GB of the project files. I will try just rebasing it and will update soon on the results – Dani Avni Dec 17 '13 at 14:57
  • maybe I did not understand you but I tried running "git rebase --onto newroot --root d206a41" where d206a41 is the id of the very first commit. again I got out of memory error – Dani Avni Dec 17 '13 at 15:12
  • I can fix this surgically, but I'm not sure you want to go that route. It would entail creating a new repo, fetching it in as a remote, rearranging commits, and hand-editing commits and re-hashing them manually. – Gary Fixler Dec 17 '13 at 19:28