简体   繁体   中英

remove binary file on git remote after push

How can I wipe away a file in a remote git repository (created via git init --bare , after I have pushed from my local machine (which was created via git clone )? I have root access to my server. I tried ssh-ing into the machine and doing git reset --hard HEAD~1 from the directory where the bare repo was made, but I get an error message stating that I am not in a work tree.

Here's my situation. I have a cross-platform project for which I keep backups on a git server on my home network. I am storing IDE files along with my source code, so that pulling the entire repository on a "fresh" machine that already has the IDE installed has everything required to open the solution or workspace, build, and run. Very late last night when my attention span was all but gone, I checked in a huge commit that contains large binary files (~35MB) that Visual Studio generates during runtime ( SolutionName.VC.db , SolutionName.VC.VC.opendb , among others). I discovered that these files slow down a git clone considerably, so I want to remove them completely from my repository.

I am willing to checkout an old copy and re-commit/re-push the changes. Also, as a preventative measure, I have already added the unwanted files to my .gitignore .

You're on the right track with git reset --hard HEAD~1 , but you should be doing that in your clone, not on the server. And after you do this, you need to push to the server, with the -f option to force rewriting the history :

git reset --hard HEAD~1
git push origin master -f

After this, update the .gitignore and commit it, then add the other changes without the Visual Studio files accidentally committed earlier. Finally commit and push again, your relevant changes should be there again, and cloning should be fast again.

git rm filename 
git commit 
git push 

should do the job. This deletes the file locally as well though so don't use it for on files you just don't want to have online yet.

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