0

I was using the git enterprise in company. When I 'git push', it told me the following error.

$ git push
Counting objects: 289, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (264/264), done.
Writing objects: 100% (289/289), 9.95 MiB | 207.00 KiB/s, done.
Total 289 (delta 37), reused 0 (delta 0)
remote: Resolving deltas: 100% (37/37), completed with 4 local objects.
remote: hooks/xxxx.sh: failed with exit status 1
remote: refs/heads/master 347a6011604730df57a348f8aa166b747d9684fe 4f6d30e187b4d20ea5ba56bd9babcdf3a3b3021b
remote: We have restricted committing abc.zip filetype. 
remote: ********RESTRICTED********
remote: abc.zip
remote: **************************
To https://gitprod.xxx
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitprod.xxx

How to remove the zip file and push again, I tried a couple of ways but did not find the correct way. Thanks.

liam xu
  • 2,892
  • 10
  • 42
  • 65
  • What have you tried please? Did you do `git remove`, `git commit`, and then `git push`? – kosist Mar 18 '19 at 09:30
  • Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Mar 18 '19 at 11:47
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+file+history – phd Mar 18 '19 at 11:47

3 Answers3

1

You accidentally staged that restriced file type, so you need to unstaged it.

Use:

git reset -- <filePath>

OR

git rm --cached <filePath>

Just replace < filePath > with the actual path of the zip file.

Then, try to commit and push again. (But don't include that file in your commit.)

programmer-man
  • 365
  • 3
  • 12
  • After that, it should not be commited normally, `git commit --amend` should be used instead. – dan1st Jun 03 '19 at 07:40
1

Since your last (unpushed) commit contains the unwanted file, we need to undo it, then commit again without it :

# undo last commit (but keep changes in working tree)
git reset --soft HEAD^

# unstage your .zip file
git reset HEAD path/to/abc.zip

# commit and push again
git commit -m "Message here"
git push

(No need to push with --force since last push was rejected.)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
1

If this file was added into your last commit, it needs to be removed from this commit with git commit --amend.

Before amending just remove the file with git rm --cached abc.zip.

Attersson
  • 4,755
  • 1
  • 15
  • 29