如何重写远程历史记录

如何重写远程历史记录

本文介绍了Git:如何重写远程历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某位同事意外提交了一个大型二进制文件,该文件没有源控制权,因此导致存储库异常大.然后,他将此提交推送到公共服务器,此后又进行了其他一系列提交和推送.我正在寻找一种撤消提交的方法,或者只是从远程计算机上删除该二进制文件,以使存储库恢复到通常的大小.

A coworker accidentally committed a large binary file which has no business being in source control thus causing the repository to be unusually large. He then pushed this commit to the common server and since then there were a bunch of other commits and pushes. I'm looking for a way to undo that commit or just remove the binary file from it on the remote so that the repository would regain its usual size.

我们的通用遥控器位于assembla.com,所以我没有直接的shell访问权限,只有git.

Our common remote is at assembla.com so I don't have direct shell access to it, just git.

假设这是可能的,那么对其他下游节点的后果是什么?每个人都需要克隆一个新的存储库吗? (如果这样的话,那很好)

Assuming this is possible, what would be the consequences for other downstream nodes? Will everybody need to clone a fresh repository? (That's fine if that's the case)

推荐答案

您可以重新设置分支基础以删除错误的提交.然后,您必须使用强制推送将重新建立基础的分支推送到Assembla的存储库.然后,所有开发人员要么必须进行全新的克隆,要么要获取远程分支,然后将其本地分支硬重置为新的远程分支.

You could rebase your branch to remove the false commit. Then you have to use a forced push to push that rebased branch to the repository at Assembla. All developers then either would have to do a fresh clone or to fetch the remote branch and then do a hard reset of their local branch to the new remote branch.

基本上,命令将是(不一定是完整的):

Basically the commands would be (not necessarily complete):

要删除错误的提交,请执行以下操作:

To remove the false commit:

git rebase -i $(commit id before false commit)

git commit

git push -f origin master (assuming that the branch is master and the remote at assembla is called origin)

git rebase -i将启动交互式rebase模式,您可以在其中删除提交.

git rebase -i will start the interactive rebase mode where you can remove the commit.

要更新开发者的克隆,请执行以下操作:

To update a developer's clone:

git fetch

git reset --hard origin/master

或者只是重新做

git clone $(repositoryurl)

大胖子来了:

执行此操作时,一定要在进行更改之前通知所有开发人员提交并推送他们的工作.然后从旧的存储库中进行备份,以便在出现任何问题的情况下将其还原

这篇关于Git:如何重写远程历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:16