0

I recently made a new directory on my local and copied all my changes from another project using a different source control into this new directory.

Inside the new directory I did

git remote add origin git@github.com/user/repo.git //ssh url to my empty Github Repo

Afterwards, I did git status then git add all and git commit. Finally I did git push and I kept getting an error about a large file not being able to push to Github. For this I did git lfs install and git lfs track "*.[filename]" but this didnt seem to work so I just deleted it from my new directory. After deleting it, I did git status again and committed the deletions of these files. However, when I push, I still get the error about the large files and checking out the lfs tool. When I go into my new directory, the large files git is complaining about is not there anymore.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
henhen
  • 1,038
  • 3
  • 18
  • 36

2 Answers2

1

You might try resetting the repo back to before you first committed the large files:

git reset HEAD~2 --soft

then get things sorted out, commit, and push again.

Another way to do it would be with filter-branch, as per the git man page:

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits:

git filter-branch --tree-filter 'rm filename' HEAD

Reason this is happening is that, even though you have now removed those files, they still were part of that first commit. Git wants to keep a full history of the repository (hey, that's one of reasons you want to use it, right?) and so it keeps those files as part of that commit history.

Community
  • 1
  • 1
Z4-tier
  • 7,287
  • 3
  • 26
  • 42
1

After deleting it, I did git status again and committed the deletions of these files. However, when I push, I still get the error about the large files and checking out the lfs tool. When I go into my new directory, the large files git is complaining about is not there anymore.

I assume you mean that you did git rm on the large file. This removes the file from the current working directory and after you git commit adds a commit that shows the file was removed. However, the commit where you added the large file still remains in the history in your git repository. This means that when you git push, it will still try to push the commit that added the large file.

If you added the large file recently, you can use git reset to reset your current branch to a commit before you added it. Note that this will remove all changes since that commit. If you have other changes you want to keep, then you need to use git filter-branch or a 3rd party tool. How to remove/delete a large file from commit history in Git repository? has a very good description about how to do this.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • I haven’t been able to push successfully to remote yet due to the large files. I didn’t do git rm, i just went into the folder and deleted it, but git status still tracked it – henhen Oct 16 '19 at 23:15
  • I'm guessing you deleted it and then did a `git add .`, which will accomplish the same thing. All you need to do then is use either of the methods I described in the other answer and you should be set. – Z4-tier Oct 16 '19 at 23:25
  • @henhen Yes, as soon as you commit a file, it is forever and always tracked by git. By this, I mean that there is now one or more commits in the git history that contain that file and changes to it. To completely remove the file from history, you need to fillow the suggestions in my second paragraph or in Z4-tier's answer. – Code-Apprentice Oct 17 '19 at 16:03