简体   繁体   English

git:所有本地分支都在遥控器后面。 如何将它们全部带到远程状态?

[英]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. 剩余:即使branchnameorigin/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/branchnamebranchname到在所有提交origin/branchname出现在branchname

I use git up for this. 我为此使用git Apart from updating all your local branches, it will also stage and unstage any local changes you have. 除了更新所有本地分支机构外,它还会暂存和取消您拥有的任何本地更改。 Saved me quite a few key strokes since I've been using it. 自从我使用它以来,我保存了很多关键笔画。

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

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