我如何正确强制Git推送? [英] How do I properly force a Git push?
问题描述
我设置了一个远程非裸主回购站并将其克隆到我的电脑。我做了一些本地更改,更新了我的本地存储库,并将更改推回到我的远程仓库。到目前为止,情况还不错。
现在,我不得不改变远程仓库中的某些东西。然后我在本地回购中改了一些东西。我意识到,不需要对远程回购进行更改。所以我尝试从我的本地仓库到我的远程仓库中找到 git push
,但是我收到了一个错误:
为防止您丢失历史记录,非快进更新为
拒绝在再次推送前合并远程更改。有关详细信息,请参阅git push --help
中有关快进的'Note
'部分。
我认为可能是
git push --force
会强制我的本地副本将更改推送到远程副本并使其相同。 它确实强制更新,但是当我回到远程仓库并进行提交时,我注意到这些文件包含过时的更改(主远程仓库之前的更改)。
正如我在评论到其中一个答案:
[I]尝试强制,但是当回到主服务器保存时变化,我得到过时的分期。因此,当我提交存储库是不一样的。
我该如何解决这个问题?
如果我尝试再次使用git push,我得到同样的错误。原产地< your_branch_name> --force
或者如果您有特定的回购:
git push https:// git .... --force
这会删除您以前的提交并推送您当前的提交。
这可能不合适,但如果有人在此页面发生绊倒,认为他们可能想要一个简单的解决方案......
短旗
还要注意 -f
是 - force
的缩写,所以
git push origin< your_branch_name> -f
也可以使用。
I've set up a remote non-bare "main" repo and cloned it to my computer. I made some local changes, updated my local repository, and pushed the changes back to my remote repo. Things were fine up to that point.
Now, I had to change something in the remote repo. Then I changed something in my local repo. I realized that the change to the remote repo was not needed. So I tried to git push
from my local repo to my remote repo, but I got an error like:
To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of
git push --help
for details.
I thought that probably a
git push --force
would force my local copy to push changes to the remote one and make it the same. It does force the update, but when I go back to the remote repo and make a commit, I notice that the files contain outdated changes (ones that the main remote repo previously had).
As I mentioned in the comments to one of the answers:
[I] tried forcing, but when going back to master server to save the changes, i get outdated staging. Thus, when i commit the repositories are not the same. And when i try to use git push again, i get the same error.
How can I fix this issue?
Just do:
git push origin <your_branch_name> --force
or if you have a specific repo:
git push https://git.... --force
This will delete your previous commit(s) and push your current one.
It may not be proper, but if anyone stumbles upon this page, thought they might want a simple solution...
Short flag
Also note that -f
is short for --force
, so
git push origin <your_branch_name> -f
will also work.
这篇关于我如何正确强制Git推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!