Can I rebase a Git branch without modifying my working copy?

后端 未结 7 2017
南旧
南旧 2020-12-08 09:16

Suppose I have my \"master\" branch checked out. I\'ve committed some production changes to \"master\", and now I want to rebase my \"experimental\" branch onto the latest m

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 09:53

    Since git 2.5, an even better solution is to use a second worktree.

    A git repository can support multiple working trees, allowing you to check out more than one branch at a time.

    $ git worktree add ../second-copy experimental
    $ cd ../second-copy/
    $ git rebase master experimental
    

    And that's it. Afterwards, you can rm -rf second-copy if you want, or keep it for more rebases in the future.

    $ git rebase master experimental
    

提交回复
热议问题