简体   繁体   中英

How to remove the restricted file from git commit?

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.

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.)

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.)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM