Adrija
Adrija

Reputation: 99

Deleting one specific commit from Github

I am trying to delete a specific commit.

I accidentally deleted an important file and created a Pull Request. Now I am trying to get that file back by deleting that specific commit which is "a5baa2f8f".

I am using this specific command: git reset --hard HEAD~1

Even though it's going back to the previous commit which is "5b7580e93", which has the important file, suppose xyz, but when I am making a change in the xyz, the file xyz is not getting reflected when I am doing git status.

Also with git pull, the commit "a5baa2f8f" is getting pulled and not "5b7580e93".

I need to delete "a5baa2f8f", so that it doesn't at all show in the Pull request. Is there any way of doing it? Thanks.

Upvotes: 1

Views: 77

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521239

Perhaps the easiest option here would be to just revert the commit which deleted the file:

git revert a5baa2f8f

This would add a new commit on top of your branch which undoes the deletion. Then, you only need to push the updated branch, to update the pull request.

But this assumes that you would also be OK with undoing the entire commit, which may not be the case. To checkout/restore the deleted file at your specific commit, use:

git checkout a5baa2f8f -- path/to/yourfile

Then, add it and commit, followed by a push.

Upvotes: 3

Related Questions