Blankman
Blankman

Reputation: 267170

Removing a file after doing git commit, verify its not in the master

I added a 50mb file or so and did a git commit.

I starting doing a :

git push origin master

But mid-way I cancelled the operation.

  1. how can I remove this file from the repo even though I did a git commit (I added it to .gitignore now but its sort of late)
  2. how can I see if the file is in the master or not?

I don't want to wipe the entire commit as there are other files I want commited (and not lost).

Upvotes: 5

Views: 410

Answers (3)

Adam Dymitruk
Adam Dymitruk

Reputation: 129654

Good that you cancelled it.

Remove the giant file.

git add -A
git commit --amend -C head
git push origin yourbranch

You should be fine.

Upvotes: 2

Seth Robertson
Seth Robertson

Reputation: 31461

Step one DO NOT PUSH If you have pushed, report back after doing something drastic.

Decision: Has this been the last commit you made?

Step two--lastcommit: git commit --amend

Step two--oldercommit: read and follow the man git-rebase page for the bit about splitting commits

Step three: read and follow the man git-filter-branch page for the bit about how to compress your .git directory. Not critical and it will happen automatically eventually.

Step four: Make a clone from you current repo to double-check that the large file is not sticking around. Verify by repo size and the absence of the file.

Step five: Push

Upvotes: 0

joelittlejohn
joelittlejohn

Reputation: 11832

There's another very similar question here that describes a number of options:

Completely remove file from all Git repository commit history

The simplest solution would git's filter-branch command.

Upvotes: -1

Related Questions