简体   繁体   English

如何强制将代码从 Visual Studio 2019 推送到 GIt

[英]How to force push code from Visual Studio 2019 to GIt

I have created a new Visual Studio 2019 project.我创建了一个新的 Visual Studio 2019 项目。

When trying to push it to a Git Repo in Azure Dev Ops I get the below error当尝试将其推送到 Azure Dev Ops 中的 Git 存储库时,我收到以下错误

Error encountered while pushing branch to the remote repository: rejected Updates were rejected because the tip of your current branch is behind its remote counterpart.将分支推送到远程存储库时遇到错误:拒绝更新被拒绝,因为您当前分支的尖端位于其远程对应部分之后。 Integrate the remote changes before pushing again.在再次推送之前集成远程更改。 Failed to push the branch to the remote repository.无法将分支推送到远程存储库。 See the Output window for more details.有关详细信息,请参阅 Output window。

How can I resolve this?我该如何解决这个问题? Is there a way to force the push?有没有办法强制推送?

Based on your error message, the remote branch has some changes after your clone the repo in Visual Studio.根据您的错误消息,在您在 Visual Studio 中克隆存储库后,远程分支有一些更改。

To solve this issue, you could try the following two methods:要解决此问题,您可以尝试以下两种方法:

In Visual studio, when the see the error message, you could see the Pull/Pull and Push option in the pop-ups.在 Visual Studio 中,当看到错误消息时,您可以在弹出窗口中看到Pull/Pull and Push选项。

在此处输入图像描述

Or in the sync tab或在sync tab

在此处输入图像描述

2.Command Line scripts: Since you could run push changes in Visual stduio, the git has been installed already. 2.命令行脚本:由于您可以在 Visual stduio 中运行推送更改,git 已经安装。

cd repo path

git pull

If you couldn't see it, you could run the following commands in cmd:如果看不到,可以在 cmd 中运行以下命令:

在此处输入图像描述

Update1:更新1:

You could run the following git command in your repo file path:您可以在您的 repo 文件路径中运行以下 git 命令:

cd repo path

git pull
git add --all
git commit -m "first commit of my code"

git push -f origin master

When you run the git pull, you could check if it returns the message: Already up to date .当你运行 git pull 时,你可以检查它是否返回消息: Already up to date

If yes, you could run the git push command to directly push the changes to Azure Repo.如果是,您可以运行 git 推送命令将更改直接推送到 Azure 存储库。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM