1

I am beginner with git and i use github that has file size limit. So I had few commits and I wanted to push them to remote repo but I could not because of the file size. I removed the file and made a new commit but it still does not allow me (because of the previous commits) Is there a way to resolve this problem by reseting or erasing previous commits and making brand new or any other way? Thanks!

pretender
  • 123
  • 1
  • 6

2 Answers2

1

You can remove that big file from the history of your repo with the BFG repo cleaner tool

$ java -jar bfg.jar --strip-biggest-blobs 500 some-big-repo.git

$ cd some-big-repo.git
$ git reflog expire --expire=now --all
$ git gc --prune=now --aggressive

$ git push
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

The key to moving backwards in commit history in git is

git reset <commit>

Let's say your git graph looks like this:

* commit 3  (HEAD, branch-1)
| Adding a large file
|
|
* commit 2 (branch-2)
| Some changes
|
|
* commit 1

If you have branch-1 checked out in the above example, and do a git reset branch-2, branch-1 will move to commit 2 and the large file will become an "untracked file". All changes to tracked files will be under "Changes not staged for commit". Once you perform the reset, you can then create a new commit by "adding" or "checking out" files as you see fit. This new commit will no longer have the large file in its history and you should be able to push to your remote repository.

You can find more information about git reset here.

While resetting, previous commits will no longer be visible if they don't have a branch pointing to them. If you feel like you might want those old commits back you can, in our example, create a temporary branch pointing to commit 3. Alternatively, you can use git fsck to find your old commits again.

user3170817
  • 131
  • 3