How to reset a branch to another branch with git?

前端 未结 5 1563
走了就别回头了
走了就别回头了 2020-12-12 12:14

let\'s say that we have an hotfixes branch which was created from master. we added commits to hotfixes, but those commits were not use

5条回答
  •  爱一瞬间的悲伤
    2020-12-12 12:40

    The answers here are solid. I have needed this exact change when resetting my staging branch to master. In that case I want to both reset the origin to match master and also reset my local to match that. So here is a git alias that allows you to pass in the branch name and do both commands in one move. (It's a little dangerous)

    reorient = "!f() { git push origin +master:$1 && git reset --hard origin/$1 ; }; f"
    

    Then use it like:

    git reorient hotfixes
    

    The answers above were totally correct. But this will simply allow for fewer keystrokes and a quicker turnaround! Hope it helps.

提交回复
热议问题