using Github but in one push ,beacuse my uncareful ,I add lots of *.jar files about 30M and push to the repo ,so how can delete the *.jar,the jar make the repo very big
-
possible duplicate of [Completely remove file from all Git repository commit history](http://stackoverflow.com/questions/307828/completely-remove-file-from-all-git-repository-commit-history) – Chris Maes Apr 23 '14 at 15:56
1 Answers
Before you start: create a backup
Scenario 1: You added the jar files in the most recent commit
Follow these steps:
Delete the jar files:
git remove /path/to/file1.jar
git remove /path/to/file2.jar
...
Commit using amend
git commit --amend
Now push --force to overwrite the remote commit. Attention! do this only if no others have already pulled the commit:
git push --force origin HEAD
Scenario 2: You added the jar files not in the most recent commit
If it was not the recent commit you need to identify the commit where you added the jar files. This can be done using
git whatchanged
for example.
Then you need to rebase that commit using git rebase. Let's say the commit where you added the jars is 79755c4
git rebase -i 79755c4~1
An editor will show up. Replace pick
by edit
in the line containing 79755c4
and save.
Now delete the jar files as shown above:
git remove /path/to/file1.jar
git remove /path/to/file2.jar
...
Commit this changes using amend:
git commit --amend
Complete the rebase:
git rebase --continue
And push --force the changes to the remote branch. Again, Attention! do this only if no others have already pulled the commit!
git push --force origin HEAD
That's it.

- 152,036
- 28
- 249
- 266