git rebase after previous git merge

后端 未结 5 1921
青春惊慌失措
青春惊慌失措 2020-12-02 04:23

I have the following situation:

  • I created a clone(Y) from a main repository(X), because there were many people working on Y we didn\'t do any
相关标签:
5条回答
  • 2020-12-02 04:41

    You can take all of the changes in your branch and put them into a new commit in master with the following:

    git diff master > my_branch.patch
    git checkout master
    patch -p1 < my_branch.patch
    

    Then stage your files and commit.

    0 讨论(0)
  • 2020-12-02 04:47

    git merge --squash is now my preferred way of rebasing after a large amount of work and many merges (see this answer). If the branch you're working on is called my-branch and you want to rebase from master then just do the following:

    git checkout my-branch
    git branch -m my-branch-old
    git checkout master
    git checkout -b my-branch
    git merge --squash my-branch-old
    git commit
    
    0 讨论(0)
  • 2020-12-02 04:49

    Two remarks:

    • you can rebase your own (non yet pushed) work as many time as you want on top of newly fetched commits.
    • You could avoid the merge conflicts (during rebase) if you had activated git rerere, which is done for this kind of situation.
      http://git-scm.com/images/rerere2.png See more at git rerere.
    0 讨论(0)
  • 2020-12-02 04:50

    Rebasing to get a "clean" history is overrated. The best way if you want to preserve history is just to do the merge instead of a rebase. That way if you ever need to go back to a revision, it is exactly the same as the one you tested during development. That also solves your issue about the previously solved merge conflicts.

    If you don't care about preserving history, you can create a new branch off of master, check it out, then do a git read-tree -u -m dev to update your working tree to match the dev branch. Then you can commit everything into one big commit and merge it into master as normal.

    0 讨论(0)
  • 2020-12-02 05:00

    Regarding the replay of merge conflicts, you can use git rerere to maintain a database of how merge conflicts have already been solved, so that performing a rebase that results in the same conflicts will have the laborious parts done for you automatically.

    https://hackernoon.com/fix-conflicts-only-once-with-git-rerere-7d116b2cec67

    git config --global rerere.enabled true

    The one thing to look out for is that if you resolved something incorrectly it will be automatically borked for you next time too, and you may not really realize it.

    More formal documentation here: https://git-scm.com/docs/git-rerere

    0 讨论(0)
提交回复
热议问题