Avoid unwanted merge commits and other commits when doing pull request on GitHub

前端 未结 5 802
萌比男神i
萌比男神i 2021-01-31 10:10

I forked a project on Github.

Let the remote upstream be upstream and my remote repository be origin. My local master branch is se

相关标签:
5条回答
  • 2021-01-31 10:15

    If I understand your question, you want to get rid of the intermediate/throwaway commits that you did in your branch. Try something like this:

    git checkout -b for-upstream remotes/origin/master (create a new branch from the upstream origin)
    git cherry-pick <sha-of-the-one-commit-you-want-to-submit> (fix any conflicts if necessary)
    

    this should give you a local "for-upstream" branch which contains just the upstream master + your 1 commit. You can then submit that branch for pull request

    0 讨论(0)
  • 2021-01-31 10:33

    Would this work: Create a separate branch with just the commit you want and issue a pull request on that branch.

    0 讨论(0)
  • 2021-01-31 10:38

    Instead of merging you want to rebase. You can do this manually, or automatically when pulling.

    git pull --rebase upstream master
    git push --force origin master
    

    Once you've started doing merges though this will get hard to do, you'll need to reset the branch back to before you did a merge commit.

    0 讨论(0)
  • 2021-01-31 10:39

    This looks like an answer to your question (section "Update 2011-04-15" of the topic):

    Git workflow and rebase vs merge questions

    Micah describes the technique of squash merges which let you merge changes from your feature branch as a single commit to the master branch.

    0 讨论(0)
  • 2021-01-31 10:40

    On Github, You can't create a pull request for a single specific checkin on a branch that has multiple checkins separating it from upstream.

    Create a branch specifically for each pull request you intend to make. This allows you to continue working without fear of polluting a pull request.

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