简体   繁体   English

git push错误:当前分支位于其远程对应对象的后面

[英]git push error: current branch is behind its remote counterpart

I created some file in my system , commited it and pushed it to remote repository. 我在系统中创建了一些文件,提交并推送到远程存储库。 After that i had to delete that commit using command git reset HEAD~1 . 之后,我不得不使用命令git reset HEAD~1删除该提交。

Now i have modified earlier created files and commited the code again. 现在,我已经修改了先前创建的文件,并再次提交了代码。 Now when i am trying to push the code , it failes saying: 现在,当我尝试推送代码时,它失败了:

Updates were rejected because the tip of your current branch is behind its remote counterpart.Merge the remote changes (eg 'git pull') before pushing again.

But merging will have to be done manually by seeing what i want to keep/reject and i dont want to do that. 但是合并将必须手动完成,方法是查看我要保留/拒绝的内容,而我不想这样做。

I tried to use --force option while pushing but it is also failing with error : 我在推送时尝试使用--force选项,但它也因错误而失败:

To prevent you from losing history, non-fast-forward updates were rejected.

Since no-one is using the code from remote repository and i simply want to overwrite files in remote repository.Is there a way to do this.?? 由于没有人正在使用远程存储库中的代码,我只是想覆盖远程存储库中的文件,有没有办法做到这一点?

I'm not sure what's your question though this is how you merge two commits or delete one of them. 我不确定您的问题是什么,尽管这是如何合并两个提交或删除其中之一。

It's not recommanded to rewrite history because others who already pulled your commits are going to have problem on your next push. 不建议重写历史记录,因为其他已经撤回您提交的人在您下一次推送时会遇到问题。

If you still want to delete last pushed commit you have to: 如果仍然要删除上次推送的提交,则必须执行以下操作:

git rebase -i HEAD^^

You'll see last two commits like: 您将看到最后两个提交,例如:

pick 3df324 Add README.md
pick 3245cf bump version

Merge two commits: 合并两个提交:

bump version is the last commit. bump version是最后一次提交。 You change the pick to squash then save+quit the file. 您将pick更改为squash然后保存并退出文件。 You'll see another file opened and you have to leave the text you'll want to use. 您会看到另一个文件已打开,并且必须保留要使用的文本。 Next go ahed and git push -f . 接下来去ahed和git push -f

Delete commit: 删除提交:

If you want to delete a commit simply delete it and save+quit the file. 如果要删除提交,只需将其删除并保存并退出文件即可。

You can check up Github docummentation for more informations. 您可以查看Github文档以获取更多信息。

Its better to use git pull and then resolve the conflicts. 最好使用git pull然后解决冲突。 Thers not much manual work since when there is a conflict git surrounds that part of code with <<<<<< and >>>>> . 手动操作很少,因为当发生冲突时,git用<<<<<<>>>>>包围了那部分代码。 And code before ======== is yours and code after that is from remote repository. ========之前的代码是您的,之后的代码来自远程存储库。

After that push the code. 之后,推送代码。 you wont get any error. 你不会得到任何错误。

Its not that hard to resolve conflicts. 解决冲突不是那么困难。

By following this way you wont lose any commits also. 通过这种方式,您也不会丢失任何提交。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git 推送错误“您当前分支的提示落后于其远程对应分支” - Git push error "tip of your current branch is behind its remote counterpart" 当前分支落后于其远程分支 - Current branch is behind its remote counterpart 无法git push,pull表示最新消息:当前分支位于其远程对应对象的后面 - can't git push, pull says up to date: Current branch is behind it's remote counterpart git 推送 - 更新被拒绝,因为当前分支的尖端落后于远程对应 - git push - updates rejected because tip of current branch behind remote counterpart Git分支提示位于其远程对应项的后面,并防止“推送” - Git branch tip is behind it's remote counterpart and is preventing a 'push' git-我需要推送我的最新更改,并得到我的分支提示落后于远程对等方的错误 - git - I need to push my latest changes and get error that my branch tip is behind remote counterpart 如何修复Git推送到远程副本背后 - how to fix Git push behind remote counterpart 推送到远程失败,因为“当前分支的尖端位于其远程对应部分之后” - Pushing to remote fails because “tip of your current branch is behind its remote counterpart” 当我运行“git push”时,我得到“您当前分支的提示在其远程后面”但当前分支没有上游跟踪分支 - When I run "git push" I get "tip of your current branch is behind its remote" but the current branche has no upstream tracking branch 如何解决GitHub消息,其中显示当前分支的提示位于其远程对应的后面? - How do I resolve a GitHub message that says the tip of my current branch is behind its remote counterpart?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM