Git - Moving Pushed Commits to a Different Branch

后端 未结 2 411
北恋
北恋 2020-12-23 13:34

My boss decided recently to try out an outsourcing group \"for increased capacity\" as we modify an existing application to add new features. Despite my concern that the gro

2条回答
  •  -上瘾入骨i
    2020-12-23 14:15

    Getting the branch is easy:

    git branch their-branch master
    git reset --hard master $SHA1_OF_C
    git push --force $SHARED_REPO_REMOTE
    

    This will rewrite history; it creates a new branch that is equivalent to the current master branch named their-branch, then resets your local master to point to a random SHA1 (...or branch, or tag, or whatever), and finally forcibly updates the remote repository branch to match your local branch.

    That delivers exactly the situation you want.

    Caveats: this will rewrite history, and can screw up anyone who has built off the old master. Watch out for merge problems following.

    No rebasing desired or required.

    (As an aside, I suggest you either give them a staging repository, or get them to use git send-email, or use GitHub pull requests, or otherwise prevent them pushing to master until they get it right. Which, based on your summary, might be some time away.)

提交回复
热议问题