开发者

Git remove files from repository, Github and commiters

开发者 https://www.devze.com 2023-03-24 11:47 出处:网络
Somebody accidentally checked in 80 megs worth of JPG\'s into our git repository and pushed it to github central repository.

Somebody accidentally checked in 80 megs worth of JPG's into our git repository and pushed it to github central repository.

A few people s开发者_运维技巧ince pulled these changes.

Apart from shooting the committer, what can I do to remove these images completely from the repository's history and github? And then inflict all changes on other committers.


You need to fix the changes with git reset sha_of_last_good_commit than push those backup up with git push -f. You will than need to tell everyone to pull the new changes back down.

  • If there are changes that you want to keep intermingled with the bad commits, you will need to git rebase -i to pluck out the ones you don't want before you push your fixed repo back up to github.

  • Garbage collection will eventually remove the dangling objects, or you can force it with git gc --aggressive


A more radical approach is using filter-branch.

git filter-branch --tree-filter 'rm -f *.jpg' HEAD

However you should be VERY careful when using this, as you can really mess up your repo. You should check the docs before doing anything.


Use git reset to revert the changes to before the person's commit. I don't think it is possible to force an update for people who have already pulled the changes.

git reset --hard HEAD~3 ## will reset the head to three commits ago

On second thought, the docs say:

The last three commits (HEAD, HEAD^, and HEAD~2) were bad and you do not want to ever see them again. Do not do this if you have already given these commits to somebody else.

tl;dr - Just remove the files. I don't know that you can remove the history and you cannot force something to be updated in a distributed system like git.


Even if you git reset --hard HEAD~3, and then git push --force the problem is not solved.

As gpojd cites:

Do not do this if you have already given these commits to somebody else

But well, you did. If you pushed your modified version to the central repo and someone that has fetched the version including the three bad commits from the central repo, the three bad commits are still present in his/her repo.

Everyone that has pulled from the repo when the three bad commits were present there will have to remove these wrong commits from his/her repo to get them clean again.

So tell them to fire up a console and use git fetch origin (to fetch the version from GitHub) git rebase -i origin/master to rebase their master branch on your forcibly pushed one and tell them the SHA-IDs of the commits they will have to delete.

0

精彩评论

暂无评论...
验证码 换一张
取 消