英文:
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 将不允许您简单地推送新的真相。您将需要执行所谓的 "强制推送",在这里有描述: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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论