[英]Reflection on remote GitHub repository
ALL,全部,
I unfortunately had to perform git reset --hard
to rollback to the revision I need on my local repository.不幸的是,我不得不执行
git reset --hard
回滚到我在本地存储库上需要的修订版。 That means that all commits between the old HEAD and the revision I am resetting to will be gone.这意味着旧 HEAD 和我正在重置的修订版之间的所有提交都将消失。
Now if I do git push --force
will the same happens on the remote GitHub repository?现在,如果我执行
git push --force
会在远程 GitHub 存储库上发生同样的情况吗? And how do I preserve the same deletion on another machine?以及如何在另一台机器上保留相同的删除?
Basically I want a remote GitHub repository to look exactly the same as the local repository - all commits in between removed, and also all other machines where this repository resides deletes those commits.基本上,我希望远程 GitHub 存储库看起来与本地存储库完全相同 - 删除之间的所有提交,以及该存储库所在的所有其他机器都会删除这些提交。
Or I shouldn't be doing git reset
and need another command instead?或者我不应该执行
git reset
而需要另一个命令?
TIA!蒂亚!
PS As a sole developer on the code, I don't care about other people. PS 作为代码的唯一开发者,我不关心其他人。 So,
所以,
git push --force
git pull (on another machine)
is the right thing to do in order to remove commits both on remote and another machine?为了删除远程和另一台机器上的提交是正确的做法吗?
Yes, if you do git push --force
the remote will look like your local repository.是的,如果您执行
git push --force
远程将看起来像您的本地存储库。 However as a best practice you should do it like this:但是,作为最佳实践,您应该这样做:
git push --force-with-lease
git pull --rebase
--force-with-lease
is a safety measure to prevent you from pushing if the remote branch is newer than your branch. --force-with-lease
是一种安全措施,可防止您在远程分支比您的分支新时推送。 Imagine that in the time after you've pulled and while you did your git reset, a new commit was pushed to the repository.想象一下,在您拉取并重置 git 之后,一个新的提交被推送到存储库。 That would be overwritten with
--force
but not with --force-with-lease
.这将被
--force
覆盖,但不会被--force-with-lease
覆盖。
Even if you are working alone on your repository, you might have pushed on another machine and forgot about it when you did your force push.即使您独自在存储库上工作,您也可能已经推送到另一台机器上并且在您进行强制推送时忘记了它。
git pull --rebase
should be the default way of pulling. git pull --rebase
应该是默认的拉取方式。 Any alteration to history will be correctly applied.对历史的任何更改都将被正确应用。 And if you have local commits, they will be stacked on top of the history.
如果你有本地提交,它们将堆叠在历史之上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.