如何更新我的提交记录?

huangapple go评论72阅读模式
英文:

Beginner Question: How can I update my commits?

问题

在我的GitBash中,我编辑了提交,直到只剩下四个。

如何更新我的提交记录?

这是因为我想更新我们网站上的内容,并删除那两个关于我的文件。

如何更新我的提交记录?

我尝试直接推送,但是它显示了这个错误。

如何更新我的提交记录?

有没有快速的方法可以解决这个问题?

英文:

In my GitBash, I edited the commits until there's only four left.

如何更新我的提交记录?

That is because I want to like update what's on our website and get rid of those other two about me files.

如何更新我的提交记录?

I tried to directly push it, but it it says this.

如何更新我的提交记录?

Is there a quick way to do it?

答案1

得分: 1

由于你实际上改写了历史记录,git不会允许你简单地推送新的真相。你需要使用所谓的"force push",在这里有详细描述:https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-force-with-lease。

请注意,git push --force-with-lease origin master意味着所有检查都被跳过,因此你可能会丢失提交。但在这种情况下,似乎这正是你打算做的(删除一些提交),所以没问题。

请确保你要推送的内容是准确无误的,最好再确认多次。如果你没有其他地方的仓库副本,那么撤销这个操作可能会有些棘手。

此外,不要每次推送都使用--force-with-lease,只在真正需要的时候使用。

英文:

Since you effectively rewrote history, git will not allow you to simply push the new truth. You will need what is called a "force push", described here: https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-force-with-lease.

Please note that git push --force-with-lease origin master means all checks are skipped, and you may therefor lose commits. In this case though, that seems to be what you are intending to do (removing a few commits) so it's OK.

Please make double and triple sure that you're pushing exactly what you want to push. If you don't have a copy of the repository elsewhere, then this might be a tricky thing to revert.

Also, do not use --force-with-lease with every push, only when you really need to.

huangapple
  • 本文由 发表于 2023年8月9日 16:19:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定