我对Git还比较新。我们的组织使用Fork & Pull Model来管理主分支的更改。每个开发者都fork主分支,在添加新功能时从他们的fork中创建分支。我会关注其他开发者在自己的分支中进行的提交,有时希望将这些更改合并到我的分支中。我需要采取哪些步骤来完成这一操作?
我对Git还比较新。我们的组织使用Fork & Pull Model来管理主分支的更改。每个开发者都fork主分支,在添加新功能时从他们的fork中创建分支。我会关注其他开发者在自己的分支中进行的提交,有时希望将这些更改合并到我的分支中。我需要采取哪些步骤来完成这一操作?
首先,您需要将其他开发者的存储库添加为远程库。
git remote add otherrep uriToOtherRep
然后你从那里获取更改
git fetch otherrep
然后将远程仓库的分支合并到你的本地分支
git merge otherrep/branchname
合并愉快!
假设你目前正在处理分支 feature/feature_a
,并且你想将另一个名为 feature/feature_b
的分支所做的更改合并到 feature/feature_a
中。使用以下命令即可完成:
git checkout feature/feature_a
git merge feature/feature_b
git checkout feature/feature_b
git pull
git checkout feature/feature_a
git merge feature/feature_b
你也可以执行 "git pull" 命令,它会拉取所有分支的更改。
git pull
你可以在当前分支中运行 git merge 命令
git merge origin
<branchname>
origin <branch>
而不是'origin/<branch>'。 - Jeremy一旦你在你的仓库中有了需要的分支,例如叫做anotherdev/master
的远程分支,你可以执行git merge anotherdev/master
命令。
git fetch
的结果,尽管我无法告诉你应该如何配置你的远程仓库。 - Michael Krelin - hacker
branch1
上并且想要从branch2
检出一个文件,你可以简单地使用git checkout branch2 -- /path/to/file
。 - Christoph