简体   繁体   English

从Github删除一个特定的提交

[英]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. 我不小心删除了一个重要文件并创建了一个Pull Request。 Now I am trying to get that file back by deleting that specific commit which is "a5baa2f8f". 现在我试图通过删除特定的提交“a5baa2f8f”来恢复该文件。

I am using this specific command: git reset --hard HEAD~1 我正在使用这个特定的命令: 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 . 即使它回到之前提交的“5b7580e93”,它有重要的文件,假设是xyz,但是当我在xyz中进行更改时,文件xyz在我执行git status时没有得到反映。

Also with git pull , the commit "a5baa2f8f" is getting pulled and not "5b7580e93". 同样使用git pull ,提交“a5baa2f8f”被拉出而不是“5b7580e93”。

I need to delete "a5baa2f8f", so that it doesn't at all show in the Pull request. 我需要删除“a5baa2f8f”,以便它在Pull请求中根本不显示。 Is there any way of doing it? 这有什么办法吗? Thanks. 谢谢。

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. 然后,添加它并提交,然后按下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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