将合并的开发分支/ Remerging重新用于使用git的未改变的稳定分支 [英] Reusing a merged development branch / Remerging into an unchanged stable branch with git

查看:130
本文介绍了将合并的开发分支/ Remerging重新用于使用git的未改变的稳定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两名程序员,A& B,正在开发一个带有github托管的repo的项目:

存在分支master。



程序员A创建devBranchA基于最新的master

$ master $ git checkout -b devBranchA
$ / code> pre>

程序员B根据最新的master创建devBranchB

  master $ git checkout -b devBranchB 

他们决定尽可能将稳定的更改合并到主文件中。



同意的工作流程是:

[在devBranch上]

  git commit -m'让分支足够稳定以合并'

git checkout master

git pull origin master

git merge devBranch [修复合并冲突,如果有的话]

git checkout devBranch

git commit -m'新酷东西'

但是,如果自上次合并后没有提交到主设备,则无法合并devbranch返回到master(除非创建了新的dev分支,而不是旧的分支)



在这种情况下,当程序员B将他的工作合并到master分支,它不会成为当前想要的主分支,而是合并前的主分支。

有没有办法自动强制master分支更新自己如果没有临时提交,开发分支的头部合并?

在使用git和集中式github回购时,预期的多用户工作流程是什么?我感觉好像我没有使用git,因为它是打算使用的。

解决方案

查看 git fetch; git rebase origin / master git pull --rebase ,都遵守主存储库中提交的顺序,坚持本地提交顶部。无论如何,您并不关心本地分支机构的本地提交顺序,因为只有您拥有它们。尝试一下,但小心使用,例如在重新绑定之前复制一个分支,直到您习惯了。



一般而言,您正在讨论git工作流程,并且我发现有两个常规工作流程你应该熟悉。请注意,我正在谈论如何最小化冲突的个人经验:


  • 第一个工作流程(用于最简洁的提交历史记录,推送冲突的负担通常是未提交的代码)

  • 合并工作流程(有时会发生很多会发生冲突的更改时更简单,我通常将其仅用作后备)


    示例初始工作流程



      git checkout master // For为争论起见,假设您当地主人的最新承诺来自8月1日或类似的东西。 
    git分支temp_branch //主副本
    git checkout temp_branch
    git add changedFiles; git commit changedFiles; //从11月2日起改变。

    git log //现在你的开发分支在其他分支上面有一个新的提交。

    git log origin / master //您从源存储库master分支中获取提交列表。

    通常,我使用origin / master进行开发登台,其中git标签代表生活提交发布。

    现在问题出现在哪里,以及工作流程的选择在哪里发挥作用:比方说,有一个提交来自另一个dev master从十月十五号开始提交。也许它是由另一个开发人员提交的,也许是由你自己提交的。

    您的选择:合并或重新绑定。

    合并



    引入一个额外的提交,使您的本地(未卸载)分支开发历史超过规范(原始/主数据)历史记录,导致冲突其他分支。基本上你会说我的提交订单将与主分支提交订单混合在一起,而不是重新订购提交历史。

      git merge origin / master //合并提交引入
    ... //解决所有冲突,并最终确定合并提交。
    git checkout master; git rebase temp_branch //将更改移至主。
    git push origin / master //将更改(包括合并提交)传递给原始/主

    最后,提交历史记录将如下所示:8月 - 10月 - 11月 - MergeCommit



    Rebase



    没有额外的提交,荣誉已经在本地提交的规范库(origin / master)中提交,发生的冲突通常会在开发人员尚未提交的提交时发生(因此没有其他人可以考虑)。

      git rebase origin / master // 
    ... //解决所有冲突...
    git rebase - -continue或git rebase --abort
    ... //解决所有冲突...
    git checkout master; git rebase temp_branch //获取分支变更而不向主人提交合并提交。
    git push //将所有更改推送到规范存储库。

    注意:如果您最终必须执行两个以上的冲突解决方案,那么 - 这是一个好的时间到 git rebase --abort ,然后回到做一个合并。






    尝试一下这个过程,看看它对您是否合理!这需要一些实验,然后才能真正获得适合您在git中开发的策略,我想是因为一旦您分散开发,还有更多的方法。


    Two programmers, A & B, are working on a project with a github hosted repo:

    Branch master exists.

    Programmer A creates devBranchA based on the latest master

    master$ git checkout -b devBranchA
    

    Programmer B creates devBranchB based on the latest master

    master$ git checkout -b devBranchB
    

    They decide to merge stable changes into master whenever possible.

    The agreed workflow is:

    [on devBranch]

    git commit -m 'Stuff to make branch stable enough to merge'
    
    git checkout master
    
    git pull origin master 
    
    git merge devBranch [fix merge conflicts if any]
    
    git checkout devBranch
    
    git commit -m 'New cool stuff'
    

    However, if there have been no commits to master since the last merge, it is then not possible to merge the devbranch back into master (unless a new dev branch was created, rather than the old one reused)

    In this case, when Programmer B comes to merge his work into the master branch, it will not be the current intended master, but the state of master before the merge.

    Is there a way to automatically force the master branch to update itself to the head of the dev branch on merge if there have been no interim commits?

    What is the intended multi-user workflow when working with git and a centralised github repo? I feel as though I am not using git as it is intended to be used.

    解决方案

    Check out git fetch;git rebase origin/master or git pull --rebase, both honor the order of the commits in the master repository because it rebases, sticking local commits on top. You don't care about the order of the local commits as much on local branches anyway because only you have them. Try it out, but use with care, e.g. duplicate a branch before rebasing until you're used to it.

    In general, you're talking about git workflow, and I've found that there are two general workflows that you should get familiar with. Be aware that I'm talking from personal experience on how to minimize conflicts:

    • Rebase-first workflow (for cleanest commit history, pushes the burden of conflicts generally to uncommitted code)
    • Merge workflow (sometimes simpler when there are a lot of changes that would conflict, I usually use this only as a fallback)

    Example Initial workflow

    git checkout master // For the sake of argument, let's say the latest commit in your local master is from august 1st or something old like that.
    git branch temp_branch // copy of the master
    git checkout temp_branch
    git add changedFiles;git commit changedFiles; // A change from november 2nd.
    
    git log // Now your dev branch has a new commit on top of an otherwise old branch.
    
    git log origin/master // You get a listing of the commits from the origin repository, the master branch.  
    

    Generally I use origin/master for development staging, with git tags standing for the commits that are made live releases.

    Now here's where the problem occurs, and where the choice of workflow comes into play: let's say there's a commit that came from another dev repository up in master, e.g. a commit from october 15th. Maybe it was commited by another developer, maybe by yourself.

    Your choices: Merge or rebase.

    Merge

    Introduces an extra commit, honors your local (unpushed) branched dev history over the canonical (origin/master) history, causes a little more potential for conflicts for others and other branches. Essentially you're saying "my commit order will be mixed with the master branch commit order" as opposed to reordering commit history.

    git merge origin/master // merge commit introduced
    ... // Resolve any conflicts, and finalize the merge commit.
    git checkout master;git rebase temp_branch // Move the changes to master.
    git push origin/master // Pushing changes, including merge commit, to origin/master
    

    At the end, commit history will look something like: August-October-November-MergeCommit

    Rebase

    No extra commits, honors commits already in the canonical repository (origin/master) over local commits, conflicts that occur will generally occur on commits that the developer has not yet commited (and thus no-one else can account for).

    git rebase origin/master // 
    ... // Resolve any conflicts...
    git rebase --continue or git rebase --abort
    ... // Resolve any conflicts...
    git checkout master;git rebase temp_branch // Get the branch changes without a merge commit into master.
    git push // Push all changes to the canonical repository.
    

    Note: If you end up having to do more than two conflict resolutions, -then- it is a good time to git rebase --abort and fall back to doing a merge.


    Try out the process, see if it makes sense for you! It takes some experimentation before you can really get tactics that work well for your development in git, I guess because there are so many more approaches once you get decentralized.

    这篇关于将合并的开发分支/ Remerging重新用于使用git的未改变的稳定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆