Jinbom Heo
Jinbom Heo

Reputation: 7400

Delete or Revert git commit in git repo server

One of my team member committed and pushed so large and many files at once (5 Gbyte) on git server accidentally. It's one commit.

And every other team members can not get the git update because it's too slow.(maybe takes 5~6 hours or more). So I think we can not delete the commit on local machines because we can not update the commit yet. (git revert, git reset etc.) Unfortunately, she got off work, so we can not access her local machine.

But, we can access the git repo server using shell.

project3.git

and the folder.

HEAD  config  description  hooks  info  objects  packed-refs  refs

So if it's possible, we want to revert or remove the commit or the file using shell command on the server directly. Then our team memebers do not need to get the update.
Is there any way to do that?

Update : We know the commit name. ex) 33aedaf55e

Upvotes: 1

Views: 61

Answers (1)

Alderath
Alderath

Reputation: 3859

NOTE: Before you do anything, you should back up a copy of the remote repository!

If you want to reset the branch in the remote repo: In the remote repo, show recent history: git log -3

* 33aedaf - (HEAD, master) commit with big file
* f18fd52 -  some other commit
* 160c78f - another commit

Set the branch ref (assuming master here) to the previous commit: git update-ref refs/heads/master f18fd52 After this, doing git fetch on the master branch will not fetch the big file. What we did was similar to a git reset --hard f18fd52.

The big file is still stored in the remote repo though. You could list unreachable objects: git fsck --unreachable And remove all unreachable objects: git gc --prune=all. Note that this will remove alll unreachable objects, so make sure the branch pointers look okay first.

Note that what we did was essentially rewriting history. If someone had already pulled the commit with the huge file and started working on it, new issues may arise when he tries to push his commit, so you should probably inform all colleagues who work with the repo about what you have done.

Upvotes: 3

Related Questions