0

I am trying to:

  • untrack two directories and their content (out/ & mybuild/) that were previously tracked
  • remove them from the remote repository
  • keep a local copy of the files inside these directories

Based on this post, I did the following:

git rm -r --cached out/
git rm -r --cached mybuild/
git commit -m "Remove directories out/ & mybuild/"

I still want an empty out/ directory in the remote repository, but do not need a mybuild/ directory. So, according to this post, I added mybuild/ to .gitignore in the main folder of the repository and created a .gitignore file inside the out/ directory that contains:

*
!.gitignore

and added the empty directory to the repository:

git add -f out/.gitignore
git commit -m "Add empty out/ directory"

After this, git ls-files does not show any files in the mybuild/ directory and only the .gitignore file is present in the out/ directory. Pushing the last commit to the remote repository however still contains untracked files in these directories:

[user@host]$ git push origin newbranch
Counting objects: 251, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (210/210), done.
Writing objects: 100% (214/214), 280.57 MiB | 4.20 MiB/s, done.
Total 214 (delta 93), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: File mybuild/src/file1.dat is 269.99 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File out/file2.dat is 188.17 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB

What am I missing? How could this be solved?

Update: db48x pointed out that, as the unwanted directories are present for a long time in my repository, removing them is a non-trivial task. Running git filter-branch to remove all cached files related to the out/ directory was not successful: checking out earlier commits and running git ls-files shows that unwanted files in out/ directory are still present.

Following the other solution by db48x, I checked out an earlier commit in which the large files that are obstructing a git push are not present (NOTE: it still contains a lot of unwanted files in the out/ & mybuild/ directories - just not the files that obstruct a git push). Then created a new branch (named minimal) and repeated the steps explained above to remove all files in the unwanted directories. This partially solved the issue: The out/ and mybuild/ directories are effectively gone and it is possible to push the 'minimal' branch to the remote repository.

The only issue that remains is updating the source files of the project to the most recent version. Merging the old branch 'newbranch' and 'minimal' is successful and a git ls-files run shows that no files in the out/ or mybuild/ directories are tracked by Git. Yet, git push origin minimal now again fails due to files in the out/ and mybuild/ directories.

I do not have a clue about the reason of the inconsistent messages between git ls-files and git push and would appreciate directions for further diagnosing of the problem.

Community
  • 1
  • 1
user2416984
  • 941
  • 1
  • 11
  • 18

1 Answers1

0

From the looks of things you've correctly introduced a commit which removes those files. Those files are still included in the previous commits, however, so they still need to be uploaded.

If you can, check out the commit prior to when those directories were mistakenly added and recommit any changes; this time making sure not to add those directories. Then use git branch -f to move the branch label(s) to these new commits. This creates a new branch with the same name as the old, and some of the same history. If you've already pushed some of the mistaken commits, pushing this new branch will also require the -f parameter to force it to update the remote branch.

Follow up:

Since this isn't a recent mistake, you'll have to break out the big guns. Git has a command filter-branch which lets you rewrite history. Check out the help page for this command, it gives exactly this scenario as the first example. Note that after you do this every commit in your repository will be modified, so once you've pushed all of your new branches anyone who had cloned the repository will have to do some work to catch up, or will have to delete their clone and recreate it.

db48x
  • 3,108
  • 24
  • 16
  • Thanks for the reply. The problem is that these directories are present in the repository since I first committed the project, so I cannot checkout to a version without these directories. Now they are getting too big and I'd like to get rid of them. I tried to make a new branch and again remove the directories, hoping that pushing a new branch (with the `-f` option) to the remote repository would be successful. Unfortunately not... – user2416984 Nov 17 '15 at 15:16
  • Related to the follow-up: Luckily I'm still the only one working on this project. So I should perform `git filter-branch 'git rm -r --cached --ignore-unmatch out/' HEAD` and the same for mybuild/? Then commit and push? This doesn't seem to work either. – user2416984 Nov 17 '15 at 16:03
  • Update: although many `rm` commands are executed using `git filter-branch`, at the end I get the following message: `WARNING: Ref 'refs/heads/newbranch' is unchanged`. – user2416984 Nov 17 '15 at 16:16