我遇到一个奇怪的问题,文件同步到我的远程仓库(TFS 2015 Git到VSTS GIT)。
我有报告1是包含“Hello”的“sample.txt”。
我在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在获取源代码步骤期间未使用master
自动更新origin/master
分支。因此,您需要通过添加命令master
来使用origin/master
分支更新本地git reset --hard 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
关于git - 同步到远程仓库时git push的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51073587/