简体   繁体   English

Git-从本地和远程仓库中删除多个先前的提交

[英]Git - Removing multiple previous commits from both local and remote repo

This has more than likely been asked before but I've gotten myself so confused trying to find the solution that I thought it better to just post the specific problem I'm trying to resolve. 这在以前很可能被问到过,但是我变得很困惑,试图找到解决方案,以为最好只是发布我要解决的特定问题。

I want to completely remove the commits crossed out (see screen grab) leaving the others untouched. 我想完全删除划掉的提交(请参阅屏幕抓取),而其他保持不变。 As you can see, these commits don't always follow each other. 如您所见,这些提交并不总是相互遵循的。 I have already pushed all these commits to remote so I'd need this to reflect there also. 我已经将所有这些提交推送到远程了,所以我也需要在此反映出来。 Is it possible to do this? 是否有可能做到这一点?

I'm relatively new to using Git so any advice would be great. 我对使用Git相对较新,因此任何建议都会很棒。 Thanks. 谢谢。

Local repo commits - SourceTree screen grab 本地回购提交-SourceTree屏幕抓取

If you have already pushed those commits, you shouldn't delete them from history. 如果您已经推送了这些提交,则不应将它们从历史记录中删除。 Doing so will cause other people problems when they pull your changes. 这样做会在其他人拉出您的更改时引起其他问题。

Instead, you can use the revert command to create a new commit and removes the changes from an earlier commit. 相反,您可以使用revert命令来创建新的提交,并从先前的提交中删除更改。 When you push this commit to the remote repository, it will have the same effect as deleting the commit, but it won't cause problems when other people pull from that repository. 当您将此提交推送到远程存储库时,它将具有与删除提交相同的效果,但是当其他人从该存储库中提取信息时,不会造成问题。

To remove the most recent commit that is crossed out in your image, enter the following command: 要删除映像中划掉的最新提交,请输入以下命令:

git revert 1e3e620

Repeat this for any other commits you want to revert, and then push all of those commits to the remote repository. 对要还原的任何其他提交重复此操作,然后将所有这些提交推送到远程存储库。

Use git rebase -i to delete the commits, then push to remote with --force . 使用git rebase -i删除提交,然后使用--force推送到remote。 (And deal with the upset coworkers who already pulled from the remote...) (并与已经从远程撤离的沮丧的同事打交道...)

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

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