What is the correct way to merge upstream without losing changes?

前端 未结 3 1269
囚心锁ツ
囚心锁ツ 2021-02-02 04:07

I\'m in a bit of a pickle.

I started development on a fork of a repo a few months ago. I made some changes. I was about to push my code back to the master as a pull re

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-02 05:08

    You should always create new branch for each Pull Request your create. Before you going to push it to github to create the request, you should rebase your branch to the latest upstream branch.

    Github says you use git merge for this, I prefer to use git rebase upstream/master if there aren't much changes, this will prevent merge commits.


    Sometimes the rebasing can't continue, because something what you have changed was already changed in the upstream branch. For instance, assume that you have a text.txtfile like:

    Lorem ipsum
    

    You create a PR to update this to Lorem ipsum! and the upstream branch already changed this to Hello World If you do a rebase, to make your code up to date before creating a request, you get a merge conflict. The file is updated with conflict markers and you can choose which version you want to use and you can even edit it, in our example we get this in text.txt:

    <<<<<<< YOUR_PR_BRANCH
    Lorem Ipsum
    =======
    Hello World
    >>>>>>> THE_UPSTREAM_BRANCH
    

    After this, add the updated files with git add and execute git rebase --continue.

提交回复
热议问题