[英]Git Reset local repository after hard push to remote
We have a continuous integration build process pointed at a source git repository. 我们有一个针对源git存储库的持续集成构建过程。 When the process runs the CI process pushes its output into a releases repository. 当流程运行时,CI流程会将其输出推送到发布存储库中。 My question revolves around the following scenario. 我的问题与以下情况有关。
What I would like to do is tell the CI server to reset the local repository match exactly the remote repo. 我想做的是告诉CI服务器将本地存储库重置为与远程仓库完全匹配。 I've looked at several similar problems and they all say to run the following commands (or very similar). 我看过几个类似的问题,它们都说要运行以下命令(或非常类似的命令)。
git fetch --all
git reset --hard [remote repository]
Even after running those commands prior to the build process, I still get the same error. 即使在构建过程之前运行了这些命令,我仍然会遇到相同的错误。 Any ideas on what I should do? 关于我应该做什么的任何想法? Or if what I want to do is even possible. 或者,如果我想做的事情甚至是可能的。
So it seems that I was potentially resetting the wrong repository. 因此,似乎我可能正在重置错误的存储库。 I have changed the commands to do the following (with the last step potentially being unnecessary) 我已更改命令以执行以下操作(最后一步可能是不必要的)
git fetch --all
git reset --hard @{u}
git pull
The @{u}
tells git to reset whatever branch is currently checked out, thus eliminating the need to specify the branch manually (which I must have been doing wrong). @{u}
告诉git重设当前已检出的任何分支,从而无需手动指定分支(我一定做错了)。
One additional item of interest. 另一项感兴趣的项目。 If you are running the commands in a power shell script (how our CI server runs these actions) you have to write the git reset as follows (as the curly braces cause parse errors). 如果您正在Power Shell脚本中运行命令(我们的CI服务器如何运行这些操作),则必须编写git reset,如下所示(因为花括号会导致解析错误)。
git reset --hard "@{u}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.