【问题标题】:Can I track origin/master in a branch featureA and push the changes to the origin/featureA我可以在分支 featureS 中跟踪 origin/master 并将更改推送到 origin/featureS
【发布时间】:2012-01-21 00:49:39
【问题描述】:

我只是在尝试开发新功能 A,但想跟上来自 origin/master 的任何提交。下面的工作吗?这是最好的方法吗?

git clone ssh://xxx/repo

git branch --track featureA origin/master

[do work on featureA and commit]

git commit -m"all changes made in featureA"

git push 

日常工作:

git pull  (pull the latest from origin/master)

[merge the new commits coming from origin/master with my local featureA changes]

git commit -m"resolved conflicts"

git push origin/featureA

当时间准备好将 featureA 合并到 master 时:

git checkout master

git merge featureA

git push origin/master

听起来对吗?

【问题讨论】:

    标签: git merge branch


    【解决方案1】:
    git checkout -b featureA origin/master #create the branch
    git push origin featureA #push it up and track it
    

    独立更新主节点。如果你没有提交任何东西(包括你的功能的合并),你甚至不需要检查它:

    git fetch
    git push . origin/master:master
    

    现在,如果您想包含这些最新更改,您可以

    git merge master
    

    当您想将更改包含在主文件中时

    git checkout master
    git merge featureA
    git push origin master #to send that up
    

    我不会使用 pull,因为我通常喜欢查看使用 git fetch 获取的内容,然后通过合并或变基或其他方式进行相应的操作。

    【讨论】:

    • 谢谢@Adam。 git push . origin/master:master 在上面做了什么。
    • 这是一个技巧。第一个参数通常是远程名称。如果您提供期间,它会指定远程与您所在的仓库相同。所以我将跟踪分支 origin/master 指向的内容推送到本地 master 分支。 :)
    • 这比 update-ref 更好,因为它检查快进,如果不是这样,则需要强制选项。
    猜你喜欢
    • 2023-03-26
    • 1970-01-01
    • 2012-05-22
    • 2014-09-01
    • 2017-04-16
    • 2011-05-20
    • 2011-09-18
    • 2020-09-07
    相关资源
    最近更新 更多