gpt4 book ai didi

git - 如何将特定分支与git merge ?

转载 作者:太空狗 更新时间:2023-10-29 14:29:09 26 4
gpt4 key购买 nike

注意:这以某种方式链接到 this question但它需要额外注意分支。

假设我有一个 Github 项目 https://github.com/basjj/myproject.git在我的电脑上有 2 个分支(masterfeature1)和一个本地存储库。

名为 blah 的用户提出了 pull 请求。他在 https://github.com/blah/myproject.git 上有 3 个分支(masterfeature1feature2) .

案例#1

我想在我的电脑上试试他的feature2分支,稍微修改一下,然后 merge 到我自己的master中。 以下命令是否正确?

git checkout -b feature2
git pull https://github.com/blah/myproject.git # it pulls only his feature2 branch or all?
# review the new files, make changes, etc.
git add .
git commit
git checkout master
git merge feature2

第二行(git pull...)是 pull 他所有的分支还是只 pull 他的feature2
其他:用户 blah 会出现在 Github 的 contributor list 中吗?还是不是?

案例#2

我想在我的电脑上试试他的feature1分支,稍微修改一下,然后 merge 到我自己的master中。 如果我自己已经有一个 feature1 分支,我不想覆盖(!),该怎么做?

最佳答案

所有分支都在它们自己的命名空间中,基于远程名称。

所以最好为你想试用的 repo 添加一个远程:

git remote add blah https://github.com/blah/myproject.git

然后你可以从blah中获取

git fetch blah

然后从 blah/feature2 创建你的 feature2:

git checkout -b feature2 blah/feature2

至于feature1,你可以简单地将blah/feature1 merge 到你的master
或者您可以创建自己的本地分支:

git checkout -b blah_feature1 blah/feature1

关于git - 如何将特定分支与git merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40578093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com