繁体   English   中英

同步到远程仓库时git push问题

[英]Issue with git push while syncing to remote repo

我面临一个奇怪的问题,文件同步到我的远程仓库(TFS 2015 Git到VSTS GIT)。

我的报告1是'sample.txt',其中包含'Hello'。 我在cmd中使用这些命令:

git clone 
git remote add vsts PAT 
git checkout master 
git push vsts master

它没有问题,当我将文件从Hello修改为Hello 1 - >执行相同的CMD时,我可以看到远程仓库中的所有更改。

现在,我在PowerShell中使用了相同的CMD

if ( $(git remote) -contains 'vsts' )
{
  git remote rm vsts 2>&1|Write-Host
  echo 'VSTS Account removed'
}
git remote add vsts https://Personal%20Access%20Token:TOKEN@my.visualstudio.com/teamproject/_git/repo 2>&1|Write-Host
git checkout ${env:BUILD_SOURCEBRANCHNAME} 2>&1|Write-Host
git push  vsts ${env:BUILD_SOURCEBRANCHNAME} -f 2>&1|Write-Host

构建成功但它不会同步我的更改。

我常常看到错误:

Previous HEAD position was eb5c087... Updated test.ps1
Your branch is behind 'origin/master' by 9 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Switched to branch 'master'

有时,相同的CMD将来自cmd,而不是来自Powershell。

对此有何帮助?

问题是由于TFS2015在获取源步骤期间未自动更新具有origin/master master分支 因此,您需要通过添加命令git reset --hard origin/master来更新具有origin/master分支的本地master分支。

更新的PowerShell脚本如下所示:

if ( $(git remote) -contains 'vsts' )
{
    git remote rm vsts 2>&1|Write-Host
    echo 'VSTS Account removed'
}

git remote add vsts https://Personal%20Access%20Token:TOKEN@my.visualstudio.com/teamproject/_git/repo 2>&1|Write-Host

git checkout ${env:BUILD_SOURCEBRANCHNAME} 2>&1|Write-Host
git reset --hard origin/master 2>&1|Write-Host
echo 'update local branch with remote successfully'
git push  vsts ${env:BUILD_SOURCEBRANCHNAME} -f 2>&1|Write-Host

暂无
暂无

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

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