从 Git 分支获取最新信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8134105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get latest from Git branch
提问by Nageswaran
I cloned something from git repository, and switched branch
我从 git 存储库克隆了一些东西,并切换了分支
git clone ssh://11.21.3.12:23211/dir1/dir2 dir
git branch branch1
I did some modification in my local, and committed it. And somebody else also done clone and he pushed it in git repository.
我在我的本地做了一些修改,并提交了它。其他人也完成了克隆并将其推送到 git 存储库中。
Now I want the clone copy of branch1 in my local, (means don't want my update, but his update)
现在我想要我本地的 branch1 的克隆副本,(意味着不想要我的更新,而是他的更新)
回答by CharlesB
Your modifications are in a different branch than the original branch, which simplifies stuff because you get updates in one branch, and your work is in another branch.
您的修改位于与原始分支不同的分支中,这简化了工作,因为您在一个分支中获得更新,而您的工作在另一个分支中。
Assuming the original branch is named master
, which the case in 99% of git repos, you have to fetch the state of origin, and merge origin/master
updates into your local master
:
假设原始分支名为master
,在 99% 的 git repos 中都是这种情况,您必须获取原始状态,并将origin/master
更新合并到本地master
:
git fetch origin
git checkout master
git merge origin/master
To switch to your branch, just do
要切换到您的分支,只需执行
git checkout branch1
回答by Headshota
use git pull:
使用 git pull:
git pull origin yourbranch
回答by Shahbaz
Although git pull origin yourbranch
works, it's not really a good idea
虽然git pull origin yourbranch
有效,但这不是一个好主意
You can alternatively do the following:
您也可以执行以下操作:
git fetch origin
git merge origin/yourbranch
The first line fetches all the branches from origin, but doesn't merge with your branches. This simply completes your copy of the repository.
第一行从原点获取所有分支,但不与您的分支合并。这只是完成了您的存储库副本。
The second line merges your current branch with that of yourbranch
that you fetched from origin
(which is one of your remotes
).
第二行将您当前的分支与yourbranch
您从中获取的分支origin
(这是您的 之一remotes
)合并。
This is assuming origin
points to the repository at address ssh://11.21.3.12:23211/dir1/dir2
这是假设origin
指向地址处的存储库ssh://11.21.3.12:23211/dir1/dir2
回答by Robin clave
If you have forked a repository fro Delete your forked copy and fork it again from master.
如果您从仓库分叉了一个存储库,请删除您的分叉副本并从 master 再次分叉它。