英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论