[英]git: all local branches are behind the remote. How can I bring them all up to the remote state?
I've cloned a remote repository which has several branches, worked on one of those branches, committed the changes and pushed. 我克隆了一个远程存储库,它有几个分支,在其中一个分支上工作,提交更改并推送。 After a time interval during which colleagues have modified the remote repository further (and during which I've possibly forgotten how to use git), I need to make more changes.
在一段时间间隔之后,同事们进一步修改了远程存储库(在此期间我可能忘记了如何使用git),我需要进行更多更改。 I don't need to keep any local changes.
我不需要保留任何本地更改。 First I try to bring my local repo up to date by doing
首先,我尝试通过这样做来更新我的本地回购
git fetch --all
then I try to switch to the required branch by 然后我尝试切换到所需的分支
git checkout -f branchname
but git says 但是git说
Your branch is behind 'origin/branchname' by 85 commits, and can be fast-forwarded.
So I take that to mean that my local branch is stuck somewhere behind the commit corresponding to the equivalent remote branch, despite doing a fetch that I hoped would make my repo equal to the remote one. 所以我认为这意味着我的本地分支卡在对应于等效远程分支的提交后面的某处,尽管做了一个我希望使我的repo等于远程分区的提取。 What's the clearest and most straightforward way to do this?
什么是最清楚,最直接的方法? I could start with a new clone, but that seems a bit crude.
我可以从一个新的克隆开始,但这看起来有点粗糙。
在git checkout -f branchname
,执行git pull origin branchname
You just have to run : 你只需要运行:
git merge origin/branchname
Why ? 为什么?
With git fetch --all
, you've already retrieve all commits made by your colleagues. 使用
git fetch --all
,您已经检索了同事提交的所有提交。 You just have to integrate them into your local branch. 您只需将它们集成到本地分支中即可。 Since it says that your branch can be fast-forwarded, you simply have to run
git merge origin/branchname
. 既然它说你的分支可以快进,你只需要运行
git merge origin/branchname
。
Remainder : even if branchname
and origin/branchname
are linked together (we say that branchname
tracks origin/branchname
), they are not the same. 剩余:即使
branchname
和origin/branchname
链接在一起(我们说branchname
跟踪origin/branchname
),它们也不一样。 So your have to merge (or rebase) origin/branchname
on branchname
to have all commits in origin/branchname
appears in branchname
所以,你必须合并(或重订)
origin/branchname
上branchname
到在所有提交origin/branchname
出现在branchname
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.