【问题标题】:Issue with git push while syncing to remote repo同步到远程仓库时 git push 的问题
【发布时间】:2018-12-06 23:41:42
【问题描述】:

我面临一个奇怪的问题,文件同步到我的远程仓库(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。

这方面有什么帮助吗?

【问题讨论】:

  • 答案是否帮助您解决了问题?如果是,你能标记答案吗?它也将使遇到类似问题的其他人受益。

标签: git powershell cmd azure-devops


【解决方案1】:

该问题是由 TFS2015 在获取源步骤中没有自动更新 master 分支和 origin/master 引起的。因此,您需要通过添加命令git reset --hard origin/master 将本地master 分支更新为origin/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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-05
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 2013-03-06
    相关资源
    最近更新 更多